I'm trying to plot a parameter (i.e. RMSE) with three classes (first: land cover; second:bands, third: names). A similar question was posted here, but the y-axis is not a variable in dataframe.
I have tried as following:
library(ggplot2)
library(ggpattern)
df_data <- data.frame(type = c('Forest','Forest','Forest','Forest','Forest','Forest',
'Shrub','Shrub','Shrub','Shrub','Shrub','Shrub'),
Band = c('A','B','C','A','B','C','A','B','C','A','B','C'),
Name = c('N1','N2','N1','N2','N1','N2','N1','N2','N1','N2','N1','N2'),
RMSE = c(54.8,58.3,58.7,46.5,42.9,44.7,34.6,39.9,45.1,31.9,33.9,38.3))
df_data$type = factor(df_data$type, levels = c("Forest", "Shrub"))
df_data$Band = factor(df_data$Band, levels = c("A","B","C"))
df_data$Name = factor(df_data$Name, levels = c("N1","N2"))
theme_set(theme_bw())
p1 <- ggplot(df_data, aes(x = type, y = RMSE)) +
geom_col_pattern(position = position_dodge(width = 0.95), width = 0.8,
aes(pattern_fill = Band, fill = Name, pattern_angle = Band),
pattern_density = 0.1, pattern_size = 0.15) +
scale_fill_manual(values = c("#80B1D3", "#9CDC82", "#BEBADA", "#FDB462", "#FB8072", "#8DD3C7"))+
labs(x="", y="RMSE") + ylim(0, 60)
But the result is strange.
First, the second class "Bands" should be fill with stripes (without color), and the third class "Name" should be fill with color (without stripes). This is the figure I want to plot, which is similar to this question.