我希望能够操纵我的每一个盒子图的填充模式。我有下面的代码为我提供了一个盒子图,我试着使用ggpattern来设置一个模式,但我不能给这个图的每一列分配一个特定的模式。
我可以使用geom_boxplot_pattern创建一些模式,但我无法更改显示的模式类型以满足我的需求。
感谢任何能帮上忙的人,贝斯特,瓦伦蒂娜
g<-ggplot(data=data, aes(Instr1,seek, color=Instr1)) +
geom_boxplot(color="black", fill=col1,alpha = 0.5,outlier.shape = NA) +
geom_jitter( position = position_jitter(0.2)) +
scale_color_manual(values=c("black", "black","black", "black"))+
stat_summary(fun=mean, geom="point", shape=23, size=4,color="black", stroke = 1)+
theme_classic()+
theme(axis.title.x=element_blank(),
axis.text.x = element_blank(),
axis.ticks.x=element_blank())+
theme(axis.title.y=element_blank(),
axis.text.y = element_text(size=20,color="black"),
axis.ticks.y=element_blank())+
theme(legend.position = "none")+
ylim(-1.8, 1.8)```
g+ geom_boxplot_pattern( aes( pattern = task )) ```发布于 2021-09-23 17:04:08
我希望我理解了你的问题。这是我想出来的:
首先创建一个新列,为每个变量分配一个任务。
然后,您可以使用scale_pattern_manual()和scale_pattern_fill_manual()手动为每个任务分配图案和颜色。
#remotes::install_github("coolbutuseless/ggpattern")
library("ggplot2")
library("ggpattern")
plot_data <- iris
## create new column to assign tasks to groups of variables
plot_data$task <- ifelse(plot_data$Species == "setosa", "task1", "task2")
ggplot(plot_data, aes(x=Species, y=Sepal.Length)) +
geom_boxplot_pattern(aes(pattern = task, pattern_fill = task), pattern_density = 0.35, outlier.shape = NA) +
scale_pattern_manual(values= c("task1" = "crosshatch", "task2" = "stripe")) + # manually assign pattern
scale_pattern_fill_manual(values=c("task1" = "red", "task2" = "lightblue")) + # manually assign colors
geom_jitter(position = position_jitter(0.2), aes(color=task)) +
theme_classic()https://stackoverflow.com/questions/69302065
复制相似问题