导读
指定x轴排序的问题,不出线的问题。
一、直接绘图
library(ggplot2)
x=c("0h", "4h", "8h", "12h", "16h")
y=c(10, 20, 30, 40, 50)
data=data.frame(x, y)
ggplot(data, aes(x=x, y=y)) + geom_point(color="red") +
labs(x="time", y="number", title="up, see me") +
theme(panel.grid=element_blank(), panel.background=element_rect(color='black', fill='transparent')) +
theme(plot.title = element_text(hjust = 0.5)) +
geom_line(color="green")
二、添加连线
- 添加参数:geom_line(aes(group="")
ggplot(data, aes(x=x, y=y)) + geom_point(color="red") +
labs(x="time", y="number", title="up, see me") +
theme(panel.grid=element_blank(), panel.background=element_rect(color='black', fill='transparent')) +
theme(plot.title = element_text(hjust = 0.5)) +
geom_line(aes(group=""), color="green")
三、指定X轴排序
- 设置x为因子
data$x=factor(data$x, levels=c("0h", "4h", "8h", "12h", "16h"))
ggplot(data, aes(x=x, y=y)) + geom_point(color="red") +
labs(x="time", y="number", title="up, see me") +
theme(panel.grid=element_blank(), panel.background=element_rect(color='black', fill='transparent')) +
theme(plot.title = element_text(hjust = 0.5)) +
geom_line(aes(group=""), color="green")