统计变换练习
(1)stat_summary()
函数的默认几何对象是什么?不使用统计变换函数的话,如何使用几何对象函数重新生成以上的图?
默认几何对象为geom_pointrange()
ggplot(data = diamonds) + geom_pointrange( mapping = aes(x = cut, y = depth), stat = "summary", fun.min = min, fun.max = max, fun = median )

(2)geom_col()
函数的功能是什么?它和geom_bar()
函数有何不同?
geom_col()针对常规柱状图有x和y,geom_bar()针对计数柱状图,仅含y
(3)多数几何对象和统计变换都是成对出现的,总是配合使用。仔细阅读文档,列出所有成对的几何对象和统计变换。它们有什么共同之处?
可以查看ggplot2
(4)stat_smooth()
函数会计算出什么变量?哪些参数可以控制它的行为?
使用?stat_smooth()
查询即可
y,predicted value
ymin,lower pointwise confidence interval around the mean
ymax,upper pointwise confidence interval around the mean
se,standard error
method和formula
(5)在比例条形图中,group=1,这是为什么呢?换句话说,以下两张图会有什么问题?
设置group = 1显示类别比例做和为1
ggplot(diamonds)+geom_bar(aes(cut,..prop..,group=1))

若不设置:
ggplot(diamonds)+geom_bar(aes(cut,..prop..))

位置调整练习
(1)以下图形又什么问题?应该如何改善?
ggplot(mpg,aes(cty,hwy))+geom_point()

问题:点集重叠;改善:添加
position='jitter'
ggplot(mpg,aes(cty,hwy))+geom_point(position='jitter')

(2)geom_jitter()使用哪些参数来控制抖动的程度?
width(水平),height(垂直)
(3)对比
geom_jitter()
与geom_count()
。
ggplot(mpg,aes(cty,hwy))+geom_count()

geom_count()
用点的大小显示点的数量
(4)geom_boxplot()
函数的默认位置调整方式是什么?创建mpg数据集的可视化表示来演示一下。
默认位置调整方式:position = "dodge2"
ggplot(mpg,aes(class,hwy))+geom_boxplot()

网友评论