geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
2016-04-10 18:48
519 查看
# sample data d <- data.frame(expand.grid(x=letters[1:4], g=factor(1:2)), y=rnorm(8)) # Figure 1a, 1b, and 1c. ggplot(d, aes(x=x, y=y, colour=g)) + opts(title="Figure 1a") + geom_line() + geom_point() ggplot(d, aes(x=x, y=y, colour=g, group=g)) + opts(title="Figure 1b") + geom_line() + geom_point() ggplot(d, aes(x=x, y=y, colour=g, group=1)) + opts(title="Figure 1c") + geom_line() + geom_point()
The figure 1a does not draw any lines, while the figure 1b works well.
The key concept is “group” in aes.
The rule is simple:
geom_line() tries to connect data points that belong to same group.
different levels of factor variable belong to different group.
So, by specifying group=g in aes, the lines appear in Figure 1b.
Figure 1c would help to understand more.
In Figure 1c, all data points belong to group=1, hence all data points are connected.
REF:
http://www.markhneedham.com/blog/2015/01/30/r-ggplot2-each-group-consist-of-only-one-observation-do-you-need-to-adjust-the-group-aesthetic/
http://stackoverflow.com/questions/27082601/ggplot2-line-chart-gives-geom-path-each-group-consist-of-only-one-observation
https://kohske.wordpress.com/2010/12/27/faq-geom_line-doesnt-draw-lines/
相关文章推荐
- 承接VR外包,虚拟现实外包,北京正规公司
- 《构建之法》阅读笔记06
- elbatummI-yreuQmuSegnaR.303
- JAVA集合(2)
- 20145240 《Java程序设计》第六周学习总结
- Eclipse添加maven第三方jar包
- 常用的较优排序之快速排序,堆排序,归并排序
- Android中日历控件的使用
- R 给data.frame(dataframe)添加一列
- Android Studio开发Android问题集【持续更新】
- 大话设计模式C++实现-第22章-桥接模式
- 继承与多态的锦集
- 树状数组(搬运自维基百科)
- 作业四
- Nutch
- FZU 2150 Fire Game
- DG
- PhoneGap极光推送插件使用
- 继承和多态的那些事
- poj 1419