【问题标题】:Why is the themes function not applying changes to the ggplot?为什么主题功能没有将更改应用于 ggplot?
【发布时间】:2021-02-21 15:23:02
【问题描述】:

我想更改我的 y 轴描述的文本大小并将我的 plottitle 居中。

主题函数中编码的所有内容都没有应用于我的图表。

问题出在哪里?

finalchart = ggplot(euall,
                    aes(day, cumulative_cases_of_14_days_per_100000 ,
                        group = countriesAndTerritories)) +
  geom_bar(stat = "identity" ,
           col = "white" ,
           fill = "darkred") +
  facet_wrap("countriesAndTerritories") +
  geom_line(aes(y = rollmean(cumulative_cases_of_14_days_per_100000, 1, 
                             na.pad = TRUE), 
                col = "pink"), 
            show.legend = FALSE) +
  labs(title = "COVID infections in the European Union in September 2020" ,
       x = "\nSeptember" ,
       y = "Infections per 100'000\n" ,
       caption = "source: https://opendata.ecdc.europa.eu/covid19/casedistribution/csv") +
  theme(axis.text.y = element_text(size = 5) ,
        axis.title.y = element_text(size = 10) ,
        plot.title = element_text(hjust = 0.5)) +
  theme_minimal()

finalchart

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    问题在于您调用theme() 和theme_minimal() 的顺序。通过调用 theme_minimal() 秒,您在 theme() 中的手动设置将被覆盖。

    library(ggplot2)
    library(patchwork)
    
    p1 <- ggplot(data = cars, aes(x = speed, y = dist)) +
      geom_point() +
      ggtitle("theme_minimal second") +
      theme(title = element_text(size = 24, color = "red", face = "bold")) +
      theme_minimal()
    
    p2 <- ggplot(data = cars, aes(x = speed, y = dist)) +
      geom_point() +
      ggtitle("theme_minimal first") +
      theme_minimal() +
      theme(title = element_text(size = 24, color = "red", face = "bold"))
    
    p1+p2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多