绘制各国条形图
- temp <- aggregate(Earnings
- ~ country, data
- = star, sum)
- temp <- temp[order(temp$Earnings),]
- n <- unique(temp$country)
- temp$country <- factor(temp$country, levels
- = n)#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">这里要设置name<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">的level<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">顺序,不然ggplot<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">会对他重新排序
- theme_opts <- list(theme(panel.grid.minor = element_blank(),
- panel.grid.major.y = element_blank(),
- panel.grid.major.x = element_blank(),
- plot.background = element_rect(fill = "transparent",colour = NA),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">设置整幅图的背景透明色
- panel.border = element_blank(),
- panel.background = element_rect(fill = "transparent",colour = NA),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">设置绘图区的颜色为透明色
- axis.ticks.y = element_blank(),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">改变坐标轴刻度线行为
- axis.ticks.x = element_blank(),
- axis.text.x = element_blank(),
- axis.text.y = element_text(colour="grey20",
- size=12),
- axis.title.y = element_blank(),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">设置y<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">轴标签为空
- axis.title.x = element_blank(),
- plot.title = element_text(size=40)))
- p <- ggplot(temp,aes(x =
- country, y = Earnings)) +
- geom_bar(stat = "identity",fill = rgb(red = 0, green = 137, blue = 130, max = 255)) +
- theme_opts + coord_flip()
- +
- guides(fill=FALSE)
- #<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">设置legend<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">的行为除了上述的guides<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">方式还有theme(legend.position="none")<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">,这里我们设置了图表背景为透明色,为了方便绘制的图表能够和其他共组绘制的图表融合,我们z<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">好选择将绘图区也设置为透明,另外我们把鱼坐标轴相关的所有配件包括坐标轴标签、刻度线、坐标轴线、坐标轴名称和网格线全部设置为空,因为这样我们可以方便的将图和表融合在一起,暂时还没想到R<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">怎么把图和表融合在一起。
- #png('<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">国家',width=713,height=323,units="px",bg =
- "transparent")
- #print(p)
- #dev.off()
绘制气泡图
- temp <- aggregate(Earnings
- ~ country, data
- = star, sum)
- size <- as.data.frame(table(star$country))
- colnames(size)
- <- c("country",
- "Freq")
- temp <- join(temp,
- size)
- ## Joining by: country
- temp <- temp[order(temp$Earnings),]
- n <- unique(temp$country)
- temp$country <- factor(temp$country, levels
- = n)#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">这里要设置name<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">的level<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">顺序,不然ggplot<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">会对他重新排序
- temp <- cbind(temp,
- m = c(rep(1, length(temp[,1]))))
- theme_opts <- list(theme(panel.grid.minor = element_blank(),
- panel.grid.major.y = element_blank(),
- panel.grid.major.x = element_blank(),
- plot.background = element_rect(fill = "transparent",colour = NA),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">设置整幅图的背景透明色
- panel.border = element_blank(),
- panel.background = element_rect(fill = "transparent",colour = NA),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">设置绘图区的颜色为透明色
- axis.ticks.y = element_blank(),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">改变坐标轴刻度线行为
- axis.ticks.x = element_blank(),
- axis.text.x = element_blank(),
- axis.text.y = element_text(colour="grey20",
- size=12),
- axis.title.y = element_blank(),#<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">设置y<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:Consolas;mso-fareast-font-family:
- 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Consolas;
- mso-bidi-font-family:" times="" new="" roman";mso-bidi-theme-font:minor-bidi"="">轴标签为空
- axis.title.x = element_blank(),
- plot.title = element_text(size=40)))
- p <- ggplot(temp,aes(x =
- country, y = m, size = Freq)) +
- geom_point(colour = rgb(red = 252, green = 102, blue = 129, max = 255), fill="white") + coord_flip()
- +
- scale_size_area(max_size = 25) +
- #geom_text(data=temp,aes(x = country, y = m,
- label = Freq, size = 4)) +
- theme_opts +
- guides(size = FALSE)
- #png('<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">国家人数',width=232,height=1000,units="px",bg =
- "transparent")
- #print(p)
- #dev.off()
各行业收入比例
- temp <- aggregate(Earnings
- ~ Category, data
- = star, summary)
- write.csv(temp,
- "H:/<span lang="EN-US" style="font-family:宋体;mso-ascii-font-family:
- Consolas;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;
- mso-hansi-font-family:Consolas;mso-bidi-font-family:" times="" new="" roman";="" mso-bidi-theme-font:minor-bidi"="">自媒体/2015-07-04/Category.csv")
各行业最高收入,平均收入即summary表
相关数据和代码:http://pan.baidu.com/s/1g6kQa 密码:微信索取
关于我们,关注理性与文艺,用数据创作内容性的精致阅读,这里是数据分析挖掘人员与文艺青年的集结地,不做培训,不做鼓吹,只踏踏实实的做一个又一个数据驱动的文章,并设计机器人减轻数据分析的负担,无论你感兴趣还是想参与都可以关注,请加微信公众号大音如霜


雷达卡





京公网安备 11010802022788号







