为什么会使用GGPLOT2出现我的字幕和字幕?
我目前正在制作一些地块,显示纽约州长岛各个城镇中最常见的行业。除了我似乎无法将我想要的字幕或字幕带入最后的绘图外,该剧情本身看起来几乎完全是我想要的。这是我正在使用的代码:
hemp_occ_plot <- ggplot(aes(x = occ_cat, y = count), data = occ_hempstead)+
geom_bar(stat = "identity", fill =c("#84D6B8", "#B8574D", "#B03B70", "#5AA197", "#21262A", "#724B65", "#772684", "#052A7F", "#D08F70", "#A3B2D8", "#4B1F28", "#CEC67E", "#FE8EA4"))+
ggtitle(label = "Most Common Industries Among Hemsptead Workers", subtitle = "Showing 408,460 Civilian Workers")+
labs(x = NULL,
y = "Workers per Industry",
caption = "Source: ACS, 2019")+
theme(plot.title = element_text(family = "Arial", face = "bold", size = (15), hjust = -1, vjust = 0),
plot.subtitle = element_text(family = "Arial", size = (12), hjust = -1, vjust = 0),
axis.title.x = element_text(family = "Arial", size = (12), vjust = 1),
axis.text.x = element_text(family = "Arial", size = (10)),
axis.title.y = element_text(family = "Arial", size = (12)))+
scale_x_discrete(limit = c("Agriculture_etal","Construction","Manufacturing","Wholesale_Trade","Retail_Trade","Transportation_Utilities","Information","Finance_Insurance_Realty","Professional","Eds_and_Meds","Entertainment_Hospitality","Other","Public_Administration"),
labels = c("Agriculture, Forestry, Fishing, Hunting, and Mining",
"Construction",
"Manufacturing",
"Wholesale Trade",
"Retail Trade",
"Transportation, Warehousing, and Utilities",
"Information",
"Finance, Insurance, Real Estate, Rental and Leasing",
"Professional, Scientific, and Waste Management",
"Education, Health Care, and Social Assistance",
"Arts, Entertainment, and Hospitality",
"Other Services, Except Public Administration",
"Public Administration"))+
coord_flip()
I am currently making some plots showing the most common industries in various towns on Long Island, NY. The plot itself looks pretty much exactly how I want except I can't seem to get the subtitle or caption I want into the final plot. Here is the code I am using:
hemp_occ_plot <- ggplot(aes(x = occ_cat, y = count), data = occ_hempstead)+
geom_bar(stat = "identity", fill =c("#84D6B8", "#B8574D", "#B03B70", "#5AA197", "#21262A", "#724B65", "#772684", "#052A7F", "#D08F70", "#A3B2D8", "#4B1F28", "#CEC67E", "#FE8EA4"))+
ggtitle(label = "Most Common Industries Among Hemsptead Workers", subtitle = "Showing 408,460 Civilian Workers")+
labs(x = NULL,
y = "Workers per Industry",
caption = "Source: ACS, 2019")+
theme(plot.title = element_text(family = "Arial", face = "bold", size = (15), hjust = -1, vjust = 0),
plot.subtitle = element_text(family = "Arial", size = (12), hjust = -1, vjust = 0),
axis.title.x = element_text(family = "Arial", size = (12), vjust = 1),
axis.text.x = element_text(family = "Arial", size = (10)),
axis.title.y = element_text(family = "Arial", size = (12)))+
scale_x_discrete(limit = c("Agriculture_etal","Construction","Manufacturing","Wholesale_Trade","Retail_Trade","Transportation_Utilities","Information","Finance_Insurance_Realty","Professional","Eds_and_Meds","Entertainment_Hospitality","Other","Public_Administration"),
labels = c("Agriculture, Forestry, Fishing, Hunting, and Mining",
"Construction",
"Manufacturing",
"Wholesale Trade",
"Retail Trade",
"Transportation, Warehousing, and Utilities",
"Information",
"Finance, Insurance, Real Estate, Rental and Leasing",
"Professional, Scientific, and Waste Management",
"Education, Health Care, and Social Assistance",
"Arts, Entertainment, and Hospitality",
"Other Services, Except Public Administration",
"Public Administration"))+
coord_flip()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该更改
主题(plot.title,plot.subtitle)
调用中的设置。来自Datanovia网站: https://www.datanovia.com/en/blog/blog/ggplot-title-subtitle-subtitle-subtitle-and-caption/#:~: text = the %20DEFAULT%20GGPLOT%20个title%20 alignment,element_text(hjust%20%3D%200.5))%20。不建议在[0,1]外使用hjust或vjust值。
You should change the hjust settings in your
theme(plot.title, plot.subtitle)
call. From the Datanovia webpage: https://www.datanovia.com/en/blog/ggplot-title-subtitle-and-caption/#:~:text=The%20default%20ggplot%20title%20alignment,element_text(hjust%20%3D%200.5))%20.It's not recommended to use hjust or vjust values outside [0,1].