R 在'的组合图中缺少颜色;gg';
我正在使用R 在'的组合图中缺少颜色;gg';,r,ggplot2,R,Ggplot2,我正在使用ggarrange组合4个图,但在各个图中的所有颜色中: 我在组合图中只得到两种颜色(红色和黑色) 有没有办法保存组合图中的所有颜色 以下是制作单独绘图的功能: library(ggplot2) ward.graph <- function(df, na.rm = TRUE, ...){ ggplot(df,aes(x = year, y = remained, fill=as.factor(dplyr::desc(v)))) + geom_area(sta
ggarrange
组合4个图,但在各个图中的所有颜色中:
我在组合图中只得到两种颜色(红色和黑色)
有没有办法保存组合图中的所有颜色
以下是制作单独绘图的功能:
library(ggplot2)
ward.graph <- function(df, na.rm = TRUE, ...){
ggplot(df,aes(x = year, y = remained, fill=as.factor(dplyr::desc(v)))) +
geom_area(stat="identity", colour="black", width=1.2) +
labs(x="", y="", title=paste("ward", df$ward)) +
scale_x_continuous(breaks = seq(2020, 2050, by = 5)) +
theme(axis.title.y = element_text(angle=0)) +
theme(axis.text.x=element_text(size=rel(0.6), angle=90)) +
theme(axis.text.y=element_text(size=rel(0.6))) +
theme(plot.title =element_text(size=rel(0.6))) +
theme(plot.subtitle = element_text(hjust =0.1)) +
guides(fill=guide_legend(title="Vintages",ncol=18)) +
theme(legend.text=element_text(size=8))+
theme(legend.title = element_text(hjust = 0.5)) +
theme(legend.background = element_rect(fill = "white", colour = "black")) +
theme(legend.position="bottom")+
theme(legend.position="bottom",
plot.margin=unit(c(0,0,-0.2,0), "cm"))
}
vy1 <- subset(vy, vy$ward==1 & vy$type=="APARTMENT")
p1<- ward.graph(vy1)
print(p1)
type0="APARTMENT"
city_name="Calgary"
type_title="Apartments"
看起来geom_区域边界太厚了。以下是如何调整:
fake <- tibble(
x = 0:100,
a = 1, b = 1, c = 1, d = 1,
e = 100 - .01*x^2,
) %>% gather(series, value, -x)
ggplot(fake, aes(x, value, fill = series)) +
# Left version has default borders
geom_area(color = "black", lty = "solid") + # default seems to be size = 0.5
# Right version has thin borders
geom_area(aes(x+110), color = "black", lty = "solid", size = 0.2)
fake%聚集(系列,值,-x)
ggplot(假,aes(x,值,填充=系列))+
#左侧版本有默认边框
几何图形面积(color=“black”,lty=“solid”)+#默认值似乎是size=0.5
#右版有薄边框
几何面积(aes(x+110),color=“黑色”,lty=“实心”,尺寸=0.2)
什么包裹是从哪里来的?此外,您是否真的需要一个包含14(!)子批次的示例,以使您的问题具有可复制性?请使用您提供的样本数据重现您的示例(样本数据似乎仅针对一个子批次?)“ggarrange”来自
ggpubr
软件包。我还纠正了其他问题。看起来黑色geom_区域边界太厚,覆盖了填充区域。geom_区域中的size
参数将解决此问题。即使进行了编辑,我也无法用给定的数据集重现此问题。
install.packages("ggpubr")
library(ggpubr)
figure<- grid.draw(ggarrange(plot_list[[1]],plot_list[[2]],plot_list[[3]],
plot_list[[4]],
common.legend = TRUE, legend = "bottom"))
annotate_figure(figure,
top = text_grob(paste("Number of",type_title,"in",city_name,sep=" "),
color = "red", face = "bold", size = 10))
> dput(head(vy1))
structure(list(year = c(2018, 2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,
2018, 2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019,
2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019,
2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020,
2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2021, 2021,
2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2021, 2021, 2021), v = c(1990, 1991,
1992, 1993, 1994, 1990, 1991, 1992, 1993, 1994, 1990, 1991, 1992,
1993, 1994, 1990, 1991, 1992, 1993, 1994, 1990, 1991, 1992, 1993,
1994, 1990, 1991, 1992, 1993, 1994, 1990, 1991, 1992, 1993, 1994,
1990, 1991, 1992, 1993, 1994, 1990, 1991, 1992, 1993, 1994, 1990,
1991, 1992, 1993, 1994, 1990, 1991, 1992, 1993, 1994, 1990, 1991,
1992, 1993, 1994, 1990, 1991, 1992, 1993, 1994, 1990, 1991, 1992,
1993, 1994, 1990, 1991, 1992, 1993, 1994, 1990, 1991, 1992, 1993,
1994), ward = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4,
4, 4, 4, 4, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4,
4, 4, 4, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4,
4, 4), remained = c(4897.50570492114, 0, 0, 0, 0, 3143.11565640186,
0, 0, 0, 0, 2550.6593359167, 0, 0, 0, 0, 4358.00079250633, 0,
0, 0, 0, 4894.18607808419, 0, 0, 0, 0, 3140.98519005566, 0, 0,
0, 0, 2548.9304482556, 0, 0, 0, 0, 4355.04685283624, 0, 0, 0,
0, 4888.8318412504, 0, 0, 0, 0, 3137.54895401342, 0, 0, 0, 0,
2546.14191976995, 0, 0, 0, 0, 4350.28243401351, 0, 0, 0, 0, 4880.4658461976,
0, 0, 0, 0, 3132.1798351974, 0, 0, 0, 0, 2541.78484401111, 0,
0, 0, 0, 4342.83802960301, 0, 0, 0, 0)), row.names = c(NA, -80L
), class = c("tbl_df", "tbl", "data.frame"))
fake <- tibble(
x = 0:100,
a = 1, b = 1, c = 1, d = 1,
e = 100 - .01*x^2,
) %>% gather(series, value, -x)
ggplot(fake, aes(x, value, fill = series)) +
# Left version has default borders
geom_area(color = "black", lty = "solid") + # default seems to be size = 0.5
# Right version has thin borders
geom_area(aes(x+110), color = "black", lty = "solid", size = 0.2)