赞
踩
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))
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')
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')
改变背景色+去掉网格线
ggplot(aes(x = age), data = pf) +
geom_histogram(binwidth = 1, fill = '#5760AB')+
theme(panel.background = element_rect(fill="#DCDCDC"),
panel.grid = element_blank())
x轴字体旋转90°
+theme(axis.text.x=element_text(angle = 90,hjust = 1,vjust=0,size=8)) #hjust 控制水平对齐和 vjust 控制垂直对齐
调整坐标轴字号
+theme(axis.text = element_text(size = 5) )
查看更多作图相关变换:https://ggplot2.tidyverse.org/reference/theme.html
https://ggplot2.tidyverse.org/reference/element.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。