怎么将折线图画成间断的,中间自定义点的形状的图
今天在群里无意见看到一个人问,这种图怎么画?我第一反应pch?
后面查了才知道,并不是,而且我也不知道用ggplot2怎么实现,顿时还有点慌!!有提供意见geom_segment(),我心想哇不至于吧,最后才发现原来在基础函数plot中就是一个参数type的问题就解决了
思路来源在bird.so浏览器中搜索R line type然后显示如下
bird.so
set.seed(0); x1 <- rnorm(10); x2 <- rnorm(10); x3 <- rnorm(10)
plot(x1, type = "c", pch = 19, lty = 1, col = 1,
ylim = range(c(x1,x2,x3)))
points(x2, pch = 4, col = 2) ## only points
lines(x3, lty = 2, col = 3) ## only lines
legend(6, legend = c("x1", "x2", "x3"),
pch = c(19, 19, NA), lty = c(1, NA, 2),
col = c(1,2,3), text.col = c(1,2,3))
legend(x=8,y=2,c("x1","x2","x3"),lty=c(1,NA,2),pch=c(19, 4, NA),
cex=.8, col=c("blue","red","forestgreen"))
# 然后从上可以看出,拿数据x1举例,结合plot(type = "c") + point(pch = 4)
# 就可以合并一起
plot(x1, type = "c", pch = 19, lty = 1, col = 1,
ylim = range(c(x1,x2,x3))) ## 重点需注意type的选项,详细见?plot
points(x1, pch = 4, col = 2) ## only points
间断折线图