折线图2
当有两个连续变量(数值变量)和一个分类变量时,可以通过作出折线图来观察不同组中两者关系。
载入R包。
library(ggplot2)
创建作图数据。
mydata <- data.frame(
months = 1:6,
tree_type = rep(c("tree_1", "tree_2"), each = 6),
height = c(1, 2, 2, 3, 5, 5,
1, 3, 4, 3, 2, 2)
)
mydata
画出一个基本的。
ggplot(mydata, aes(months, height, colour = tree_type)) +
geom_line()
简单修饰。
ggplot(mydata, aes(months, height, colour = tree_type)) +
geom_line(size = 1, linetype = 1 ) +
geom_point(size = 2) +
theme_classic()
2023-02-21 16:28