作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个数据框和这个图:
df <- data.frame(Groupe = rep(c("A","B"),4),
Period = gl(4,2,8,c("t0","t1","t2","t3","t4")),
rate = c(0.83,0.96,0.75,0.93,0.67,0.82,0.65,0.73))
ggplot(data = df, mapping = aes(y = rate, x = Period ,group = Groupe, colour=Groupe, shape=Groupe)) +
geom_line(size=1.2) +
geom_point(size=5)
t1
之间的点和
t2
不是用线连接的吗?我要
t0
和
t1
待连接(蓝色或红色根据组别),
t2
和
t3
以相同的方式连接,但
t1
之间没有线和
t2
.我通过查看类似的问题尝试了几件事,但它总是弄乱我的分组颜色:/
最佳答案
手动创建新的分组变量通常不是最好的方法。因此,一种稍微不同的方法需要较少的硬编码:
# create new grouping variable
df$grp <- c(1,2)[df$Period %in% c("t2","t3","t4") + 1L]
# create the plot and use the interaction between 'Group' and 'grp' as group
ggplot(df, aes(x = Period, y = rate,
group = interaction(Groupe,grp),
colour = Groupe,
shape = Groupe)) +
geom_line(size=1.2) +
geom_point(size=5)
关于r - geom_line : How to connect only a few points,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35181228/
我是一名优秀的程序员,十分优秀!