从R中删除Legend Gplot的标准偏差

发布于 2025-02-11 12:20:53 字数 1610 浏览 2 评论 0原文

我想删除SD栏,而刻薄的传奇人物将其保留在主人公上。就我而言,我有:

”带有sd

,我想要这样的东西:

这是我的代码:

data_summary <- function(x) {
    m <- mean(x)
    ymin <- m-std.error(x)
    ymax <- m+std.error(x)
    return(c(y=m,ymin=ymin,ymax=ymax))
  }
a<-ggplot(esto,aes(x= Group, y=value,  colour = Group, fill=fluency_test),
         pattern_fill = "black",
         colour  = 'black') +
    geom_boxplot(outlier.shape = NA,lwd=1.5) +
    guides(colour = "none")+
    geom_point(position=position_jitterdodge(),alpha=0.5)+
    xlab("Group")+
    labs(y = names(features)[[i_feature]])+
    theme(axis.text.x = element_text(angle = 45, hjust = 1))+
    stat_summary(fun.data=data_summary, color="black",position=position_dodge(width=0.75), size = 1.3)+
    scale_shape_manual("Summary Statistics", values=c("Mean"="+"))+
    scale_color_manual(values=c("#7CAE00","#F8766D","#00BFC4","#C77CFF"))+
    scale_fill_manual(values=c("white","azure3"))+
    theme_gray(base_size = 18)+
    theme(legend.key.size = unit(2, "cm"),
          legend.key.width = unit(1,"cm"),legend.title=element_blank(),panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
          panel.background = element_blank(), axis.line = element_line(colour = "black"))

I would like to remove sd bars and mean from legend while keeping them on the main figure. In my case I have this:

Image with sd and mean

And I want something like this:
enter image description here

This is my code:

data_summary <- function(x) {
    m <- mean(x)
    ymin <- m-std.error(x)
    ymax <- m+std.error(x)
    return(c(y=m,ymin=ymin,ymax=ymax))
  }
a<-ggplot(esto,aes(x= Group, y=value,  colour = Group, fill=fluency_test),
         pattern_fill = "black",
         colour  = 'black') +
    geom_boxplot(outlier.shape = NA,lwd=1.5) +
    guides(colour = "none")+
    geom_point(position=position_jitterdodge(),alpha=0.5)+
    xlab("Group")+
    labs(y = names(features)[[i_feature]])+
    theme(axis.text.x = element_text(angle = 45, hjust = 1))+
    stat_summary(fun.data=data_summary, color="black",position=position_dodge(width=0.75), size = 1.3)+
    scale_shape_manual("Summary Statistics", values=c("Mean"="+"))+
    scale_color_manual(values=c("#7CAE00","#F8766D","#00BFC4","#C77CFF"))+
    scale_fill_manual(values=c("white","azure3"))+
    theme_gray(base_size = 18)+
    theme(legend.key.size = unit(2, "cm"),
          legend.key.width = unit(1,"cm"),legend.title=element_blank(),panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
          panel.background = element_blank(), axis.line = element_line(colour = "black"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2025-02-18 12:20:53

您可以通过将show.legend = false stat_summary 添加show.legend = false来防止点范围在图例中显示。

使用基于mtcars的最小preprex:

library(ggplot2)

ggplot(mtcars, aes(x = cyl, y = mpg, color = factor(cyl))) +
  geom_boxplot() +
  stat_summary(color = "black", show.legend = FALSE)
#> No summary function supplied, defaulting to `mean_se()`

“”

You can prevent the point range from being displayed in the legend by adding show.legend=FALSE to stat_summary.

Using a minimal reprex based on mtcars:

library(ggplot2)

ggplot(mtcars, aes(x = cyl, y = mpg, color = factor(cyl))) +
  geom_boxplot() +
  stat_summary(color = "black", show.legend = FALSE)
#> No summary function supplied, defaulting to `mean_se()`

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文