R 如何使用ggplot循环绘制多个图形
这是我的数据帧:R 如何使用ggplot循环绘制多个图形,r,ggplot2,R,Ggplot2,这是我的数据帧: x1 <- c(1,2,3,4) x2 <- c(3,4,5,6) x3 <- c(5,6,7,8) x4 <- c(7,8,9,10) x5 <- c(8,7,6,5) df <- c(x1,x2,x3,x4,x5) 你可以做: mapply(function(y) print(ggplot(data = df) + geom_point(aes_string(x = "x1", y = y)) + geom_smooth(aes
x1 <- c(1,2,3,4)
x2 <- c(3,4,5,6)
x3 <- c(5,6,7,8)
x4 <- c(7,8,9,10)
x5 <- c(8,7,6,5)
df <- c(x1,x2,x3,x4,x5)
你可以做:
mapply(function(y) print(ggplot(data = df) +
geom_point(aes_string(x = "x1", y = y)) +
geom_smooth(aes_string(x = "x1", y = y))), y=c("x2","x4","x5"))
注意:我使用了df你可以做:
mapply(function(y) print(ggplot(data = df) +
geom_point(aes_string(x = "x1", y = y)) +
geom_smooth(aes_string(x = "x1", y = y))), y=c("x2","x4","x5"))
注意:我使用了df,您也可以从purr
tidyverse包检查map
。您也可以从purr
tidyverse包检查map
。
mapply(function(y) print(ggplot(data = df) +
geom_point(aes_string(x = "x1", y = y)) +
geom_smooth(aes_string(x = "x1", y = y))), y=c("x2","x4","x5"))