|
- 幕布导出来的图太大。。。
- 1.6 几何对象
- geom_point, geom_smooth
- ggplot2提供30多种集合对象,ggplot2的速查表(http:// rstudio.com/cheatsheets)
- 同一张图中显示多个集合对象←←添加多个几何对象函数
- 这两组代码得到相同的结果
- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) + geom_point() + geom_smooth()
- ggplot(mpg) + geom_point( mapping = aes(x = displ, y = hwy)) + geom_smooth(mapping = aes(x = displ, y = hwy))
- p16练习题
- 1. 在http:// rstudio.com/cheatsheets找的 :折线:geom_line()
;箱线:geom_boxplot() ;直方:一个变量:geom_histogram(),两个 变量: geom_col() 分区:coord_polar × 分区应为 geom_area()
- 2. 预测:不同颜色的散点图,曲线没有周围灰色阴影(se是Display confidence interval around smooth)运行后是,预测的一样

- 3.不显示图例,删掉就显示图例
- 4.se的 Display confidence interval around smooth,标准差的
- 5. 二者无差
- 6. 照虎画猫,代码都写出来了~哈哈~这几个代码分别应该是:(书中图片比较小,各个点都粘在一起了,我以为是点的size比较大,后面都改成size = 4)
- ggplot(mpg, mapping = aes(x = displ, y = hwy)) + geom_point (size = 4) + geom_smooth(se = FALSE)
- ggplot(mpg ) + geom_point(mapping = aes(x = displ, y = hwy, size = 4), show.legend = FALSE) + geom_smooth(mapping = aes( x = displ, y = hwy, group = drv),se = FALSE) (最开始把se 放在函数里了,怎么试都不对。。) 书中答案:ggplot(mpg, aes(x = displ, y = hwy)) + geom_smooth(mapping = aes(group = drv), se = FALSE) +
- ggplot(mpg ) + geom_point(mapping = aes(x = displ, y = hwy, color = drv)) + geom_smooth(mapping = aes( x = displ, y = hwy, color = drv),se = FALSE)
- ggplot(mpg ) + geom_point(mapping = aes(x = displ, y = hwy, color = drv)) + geom_smooth(mapping = aes( x = displ, y = hwy),se = FALSE)
- ggplot(mpg ) + geom_point(mapping = aes(x = displ, y = hwy, color = drv)) + geom_smooth(mapping = aes( x = displ, y = hwy, linetype = drv),se = FALSE)
- ggplot(mpg ) + geom_point(mapping = aes(x = displ, y = hwy, color = drv, size = 4)) 答案:ggplot(mpg, aes(x = displ, y = hwy)) + geom_point(size = 4, color = "white") + geom_point(aes(colour = drv)) ←书中印刷没看见周围的白圈。。
- 1.7 统计变换
- 绘图时,用来计算新数据的算法成为stat() 统计变换。
- 几何对象函数和统计变换函数可以互换使用。
- p21练习
- 1. 默认的几何对象是geom_pointrange ; ggplot(diamonds) + geom_pointrange(mapping= aes(x = cut, y = depth)) × 答案: ggplot(data = diamonds) + geom_pointrange( mapping = aes(x = cut, y = depth), stat = "summary", fun.ymin = min, fun.ymax = max, fun.y = median ) stat_summary()为x的每个唯一值计算y值的摘要统计
- 2. geom_col()也是画柱状图,这个是多个变量,geom_bar()是单一变量。 答案:geom_col() 默认几何对象是identity() stat. geo_col() 默认数据已经预先处理,为x轴和y轴的的长短。 geom_bar() 默认几何对象是数量(count),默认每个变量x有多个观测值。
- 3.??
- 4. 统计: y: predicted value; ymin: lower value of the confidence interval;ymax: upper value of the confidence interval;se: standard error
- 5. If group is not set to 1, then all the bars have prop == 1. The function geom_bar() assumes that the groups are equal to the x values, since the stat computes the counts within the group. ???
|
|