R ggplot2中两个不同组的不同调色板
我正试图创建一个显示土壤湿度月垂直剖面的图,用于多个地点的观测和建模数据 到目前为止,我只能绘制一组值,无论是观察值还是建模值,如本例所示:R ggplot2中两个不同组的不同调色板,r,plot,ggplot2,colors,R,Plot,Ggplot2,Colors,我正试图创建一个显示土壤湿度月垂直剖面的图,用于多个地点的观测和建模数据 到目前为止,我只能绘制一组值,无论是观察值还是建模值,如本例所示: library(ggplot2) library(RColorBrewer) # Create customized color palette mypal <- colorRampPalette(brewer.pal(6,"PuBu")) ggplot(df1, aes(x=value, y=depth, colour=as.factor(mo
library(ggplot2)
library(RColorBrewer)
# Create customized color palette
mypal <- colorRampPalette(brewer.pal(6,"PuBu"))
ggplot(df1, aes(x=value, y=depth, colour=as.factor(month))) +
geom_path() +
facet_wrap(~ site) +
scale_y_reverse() +
scale_colour_manual(values=mypal(12)) +
theme_bw(base_size=18) +
ylab("Depth") + xlab(bquote('Soil moisture (' ~m^3~m^-3*')')) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
库(ggplot2)
图书馆(RColorBrewer)
#创建自定义调色板
mypal您可以使用交互
组合类型
和月份
:color=interaction(as.factor(month),type))
。
而不是:group=type,color=as.factor(月)
要创建红色和蓝色托盘,请使用两个mypal
功能:
mypal <- colorRampPalette(brewer.pal(6, "PuBu"))
mypal2 <- colorRampPalette(brewer.pal(6, "YlOrRd"))
mypal
# Create some random data based on the first dataset
df1 <- cbind(df1, type='observed')
df2 <- df1[1:4]
df2$value <- df2$value * 1.5
df2 <- cbind(df2, type='modeled')
df3 <- rbind(df1,df2)
# Try to plot it
ggplot(df3, aes(x=value, y=depth, group=type, colour=as.factor(month))) +
geom_path() +
facet_wrap(~ site) +
scale_y_reverse() +
theme_bw(base_size=18) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
mypal <- colorRampPalette(brewer.pal(6, "PuBu"))
mypal2 <- colorRampPalette(brewer.pal(6, "YlOrRd"))
library(ggplot2)
library(RColorBrewer)
mypal <- colorRampPalette(brewer.pal(6, "PuBu"))
mypal2 <- colorRampPalette(brewer.pal(6, "YlOrRd"))
ggplot(df3,
aes(value, depth, color = interaction(as.factor(month), type))) +
geom_path() +
facet_wrap(~ site) +
labs(title = "Soil moisture by depth and site",
subtitle = "Observed and expected data",
x = bquote('Soil moisture (' ~m^3~m^-3*')'),
y = "Depth") +
scale_y_reverse() +
scale_colour_manual(values = c(mypal(12), mypal2(12))) +
theme_classic() +
theme(legend.position = "none")