- 组距
- 数据间隔
- 填充/边框
- 轴标签
- 组距(bindwidth)/数据间隔
组距:根据最大值,最小值确定每组组距(直方图的组宽,一个里面表示多少个x轴间隔)
数据间隔:将breaks参数传给scale_x_continuous图层,包括起始点,终点和间隔(坐标轴上显示间隔)
qplot示例:
qplot(x=friend_count,data = pf,binwidth=25)+
scale_x_continuous(limits = c(0,1000),
breaks = seq(0,1000,50))
ggplot示例:
ggplot(aes(x = friend_count), data = pf) +
geom_histogram(binwidth = 25) +
scale_x_continuous(limits = c(0, 1000), breaks = seq(0, 1000, 50))
- 填充(fill)/边框(color)
qplot示例:
qplot(x=tenure,data = pf,binwidth=30,
color=I('black'),fill=I('#F79420'))
ggplot示例:
ggplot(aes(x = tenure), data = pf) +
geom_histogram(binwidth = 30, color = 'black', fill = '#099DD9')
- 轴标签:使用xlab和ylab 改变坐标轴名称
qplot示例:
qplot(x=tenure/365,data = pf,binwidth=0.25,
xlab = 'number of years using facebook',
ylab = 'number of users in sample',
color=I('black'),fill=I('pink'))+
scale_x_continuous(breaks = seq(1,7,1),lim = c(0,7))
ggplot示例:
ggplot(aes(x = friend_count, y = ..count../sum(..count..)), data = subset(pf, !is.na(gender))) +
geom_freqpoly(aes(color = gender), binwidth=10) +
scale_x_continuous(limits = c(0, 1000), breaks = seq(0, 1000, 50)) +
xlab('好友数量') +
ylab('Percentage of users with that friend count')