我很难找到一种方法来生成R中有多行的多图,但是在第二行,我希望绘图位于第一行并排的两个图的中间row ...附上我的代码和我想要的图表和图表。任何建议将不胜感激!谢谢!
pie_chart <- function(parameter, title=parameter) {
parameter_df <- parameter_results %>%
select(results = parameter) %>%
filter(results != "Not Applicable") %>%
count(results) %>% #
mutate(prop = prop.table(n), perc = paste0(round(prop * 100),"%"))
color_code <- c("Attaining" = "#99FF99", "Insufficient Information" = "#FFFF99", "Non Attaining" = "#FF9999")
parameter_df <- parameter_results %>%
select(results = parameter) %>% #keep only column for the parameter you want to plot
filter(results != "Not Applicable") %>%
count(results) %>% #
mutate(prop = prop.table(n), perc = paste0(round(prop * 100),"%"))
values <- vector(mode = "numeric", length = nrow(parameter_df))
labs <- vector(mode = "character", length = nrow(parameter_df))
colors <- vector(mode = "character", length = nrow(parameter_df))
for (i in seq_along(1:nrow(parameter_df))) {
values[[i]] <- parameter_df$prop[[i]] * 100
labs[[i]] <- parameter_df$perc[i]
colors[[i]] <- color_code[[parameter_df$results[[i]]]]
}
pie(x = values, labels = labs, col = colors, main = title,font=2,font.main=2)
CairoPDF(file = "Recreation Use", width = 10, height = 7)
m <- matrix(c(1,2,
3,4
), nrow = 2, ncol = 2, byrow = TRUE)
layout(mat = m, heights = c(0.4, 0.4, 0.1))
par(oma = c(4, 0, 4, 0))
par(mar = c(2,2,2,2))
pie_chart('e.Coli', "E.coli(freshwater\n217 AUs")
pie_chart('Enterococcus',"Enterococcus(marine water)\n132 AUs")
pie_chart('Beach Closing (Enterococcus)', "Enterococcus(beach closings)\n45AUs")
legend(x=1,y=-1,inset = 0, text.width=c(1.4,.5,.9),legend = c("Attaining","Insufficient Information","Non Attaining"), fill = c("#99FF99", "#FFFF99", "#FF9999"),border="#000000",cex=1.2,bty="n",xpd = NA,horiz=TRUE)
plot.new()
title("Figure 2.8:Assessment Results for Key Parameters Associated with Recreation Use,\nPercent(%) of AUs",line = 1, outer = TRUE,font=2)
dev.off()
图表我有:
我想要的图表: