为什么会使用GGPLOT2出现我的字幕和字幕?

发布于 2025-01-21 09:21:40 字数 2245 浏览 0 评论 0原文

我目前正在制作一些地块,显示纽约州长岛各个城镇中最常见的行业。除了我似乎无法将我想要的字幕或字幕带入最后的绘图外,该剧情本身看起来几乎完全是我想要的。这是我正在使用的代码:

    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()

Here is what the plot looks like:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恋你朝朝暮暮 2025-01-28 09:21:40

您应该更改主题(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。

    hjust and vjust: number in [0, 1], for horizontal and vertical adjustment of titles, respectively.
    hjust = 0.5: Center the plot titles.
    hjust = 1: Place the plot title on the right
    hjust = 0: Place the plot title on the left

不建议在[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.

    hjust and vjust: number in [0, 1], for horizontal and vertical adjustment of titles, respectively.
    hjust = 0.5: Center the plot titles.
    hjust = 1: Place the plot title on the right
    hjust = 0: Place the plot title on the left

It's not recommended to use hjust or vjust values outside [0,1].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文