绘制
rm(list = ls()) library(ggpubr) library(ggprism) library(paletteer) plot_df = read.csv('plot_df.csv') ## 设置主题 rel_size <- 1 my_theme <- theme_prism(border = TRUE, base_size = 5) + theme(strip.text.x = element_text(size = rel(rel_size*2)), title = element_text(size = rel(rel_size*2)), legend.box.spacing = unit(1, "cm"), legend.text = element_text(size = rel(rel_size*1.5)), legend.title = element_text(size = rel(rel_size*0.5)), axis.text.y = element_text(size = rel(rel_size*2), angle = 0, vjust = 0.2), axis.text.x = element_text(size = rel(rel_size*1.6), angle = 45), panel.grid = element_line(color = "gray", size = 0.15, linetype = 2), panel.spacing = unit(1, "lines"), plot.caption = element_text(size = rel_size*8)) # 绘图 p <- ggplot(plot_df, aes(x = log10(mean_gdp_per_capita), y = mean_access_perc)) + # coord_trans("log10") + geom_point(data = plot_df, aes(size = mean_death_perc, fill = continent), pch = 21) + geom_smooth(method = "loess") + scale_fill_paletteer_d("colorblindr::OkabeIto") + ggpubr::stat_cor(method = "spearman", aes(label = paste(..rr.label.., ..p.label.., sep = "~")), color = "red", geom = "label", label.x = 3.8, label.y = 5) + # facet_wrap(vars(continent),drop = TRUE) + scale_y_continuous(breaks = c(0, 25, 50, 75, 100)) + my_theme + ggtitle("Access to clean energy is associated with GDP") + labs(x = "Log10 of Average GDP per capita", y = "Average % access to clean fuels/tech", fill = "Continent", size = "Average % Death", caption = "Spearman correlation\nAveraged values over years 1990-2019\nData source: OurWorldInData.org") p ggsave(plot = p, filename = 'week1.pdf',width = 5,height = 4)
参考
https://github.com/nicholas-camarda/tidytuesda