geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?

# 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:

  1. geom_line() tries to connect data points that belong to same group.
  2. 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/

时间: 2024-08-26 04:08:11

geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?的相关文章

R语言学习 - 线图绘制

线图是反映趋势变化的一种方式,其输入数据一般也是一个矩阵. 单线图 假设有这么一个矩阵,第一列为转录起始位点及其上下游5 kb的区域,第二列为H3K27ac修饰在这些区域的丰度,想绘制一张线图展示. profile="Pos;H3K27ac -5000;8.7 -4000;8.4 -3000;8.3 -2000;7.2 -1000;3.6 0;3.6 1000;7.1 2000;8.2 3000;8.4 4000;8.5 5000;8.5" 读入数据 profile_text <

sql篇 select from where group by having order by

以前,自己总是记不住如何用group by,如何用order by,什么时候用group by,什么时候用order by,什么时候两者一起用,怎么用,谁先谁后,现在,我们就一起来说一下Select   from   where   groupby   having   order by 的那些事,简单的总结一下,加深一下自己的印象,也给有需要的人提供点资源 Select   from   where   groupby   having   order by ,不用说,select from肯

C# LINQ 详解 From Where Select Group Into OrderBy Let Join

目录 1. 概述 2. from子句 3. where子句 4. select子句 5. group子句 6. into子句 7. 排序子句 8. let子句 9. join子句 10. 小结 1. 概述 LINQ的全称是Language Integrated Query,中文译成"语言集成查询".LINQ作为一种查询技术,首先要解决数据源的封装,大致使用了三大组件来实现这个封装,分别是LINQ to Object.LINQ to ADO.NET.LINQ to XML.它们和.NET

SQL group by底层原理——本质是排序,可以利用索引事先排好序

转自:http://blog.csdn.net/caomiao2006/article/details/52140993 由于GROUP BY 实际上也同样会进行排序操作,而且与ORDER BY 相比,GROUP BY 主要只是多了排序之后的分组操作.当然,如果在分组的时候还使用了其他的一些聚合函数,那么还需要一些聚合函数的计算.所以,在GROUP BY 的实现过程中,与 ORDER BY 一样也可以利用到索引. 在MySQL 中,GROUP BY 的实现同样有多种(三种)方式,其中有两种方式会

GROUP BY语句与HAVING语句的使用

一.GROUP BY GROUP BY语句用来与聚合函数(aggregate functions such as COUNT, SUM, AVG, MIN, or MAX.)联合使用来得到一个或多个列的结果集.语法如下: SELECT column1, ... column_n, aggregate_function(expression) FROM tables WHERE predicates GROUP BY column1, ... column_n; 举例 比如说我们有一个学生表格(s

SQL中Group By的使用

SQL中Group By的使用 1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简单Group By 示例1 select 类别, sum(数量) as 数量之和 from A group by 类别 返回结果如下表,实际上就是分类汇总. 4.Group By 和 Order By 示例2 select 类别, sum(数量) AS 数量之和 fr

sql中group by使用(转发)

1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By All 7.Group By与聚合函数 8.Having与Where的区别 9.Compute 和 Compute By 1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”,然后针对若干个“小区域”进行数据处理. 2.原始表 3.简单Group

group by having where order by

1group by *在返回集字段中,这些字段要么就要包含在Group By语句的后面,作为分组的依据:要么就要被包含在聚合函数中. select 类别, sum(数量) as 数量之和 from A group by 类别 select 类别, sum(数量) AS 数量之和 from A group by 类别 order by sum(数量) desc select 类别, 摘要, sum(数量) AS 数量之和 from A group by 类别, 摘要 group by all 首先

linq group join

本篇介绍Linq的Group和Join操作,继续使用<Linq 学习(3) 语法结构>中介绍的数据源. GroupGroup是进行分组操作,同SQL中的Group By类似.原型如下: public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(     this IEnumerable<TSource> source,     Func<TSourc