으로 변경하십시오. 세 개의 매개 변수 x, y, z가있는 function_3d가 있다고 가정합니다. 함수가 정의된다고 가정 다음ggplot2에서 두 번째 그룹의 제목을 R
function_3d <- function(x, y, z) {
return(x + y * 10 + z * 100)
}
I 서열에 x의 ggplot2를 사용하여이 기능을 플롯하고 (0, 10, 1) Y는 C의 값을 갖는다 (1, 3, 5, 7) z는 c (2, 4, 6)의 값을가집니다. 여기
내 접근 방식 :require('ggplot2')
require('dplyr')
function_3d <- function(x, y, z) {
return(x + y * 10 + z * 100)
}
x_vec <- seq(0, 10, 1)
y_vec <- c(1, 3, 5, 7)
z_vec <- c(2, 4, 6)
allframes <-
lapply(z_vec, function(inp.z.val) {
(lapply(y_vec, function(inp.y.val)
{
data.frame(
x = x_vec,
y = function_3d(x = x_vec,
y = inp.y.val,
z = inp.z.val),
group_y = inp.y.val,
group_z = inp.z.val
)
}))
})
# Bind all the frames
# Note: we can use dply::bind_rows instead of rbind
df.out <- do.call(rbind, do.call(rbind, allframes))
ggplot(df.out,
aes(
x = x,
y = y,
shape = factor(group_y),
colour = factor(group_z),
group = interaction(group_y, group_z)
)) +
geom_line(aes(linetype=factor(group_y)), alpha = .9, size = 1) +
scale_x_continuous(name = "X Label") +
scale_y_continuous(name = "Y Label") +
ggtitle("Plot Title") +
scale_colour_brewer(palette = "Set1") +
labs(aes(colour = "Label of each plot z")) +
theme(legend.key.width=unit(3, "line"))
그리고 그 결과는 다음과 같습니다
는지금 나는 두 가지 질문이있다 : 나는 Y의 레이블을 변경할 수있는 방법
1) 그룹 (나는 change factor (group_y) 텍스트를 의미합니까?)
2)이 플롯을 만드는 더 좋은 방법이 있습니까? 마지막에 추가