stat_summary 的 ggplot2 图例 [英] ggplot2 legend for stat_summary

查看:38
本文介绍了stat_summary 的 ggplot2 图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建一个图例,告知红十字是平均值?

ggplot(results, aes(x=factor, y=proportionPositive)) +geom_boxplot() +stat_summary(fun.data =mean_cl_normal",颜色=红色",形状=4)

解决方案

这是一种方法:

  1. 将美学映射到形状,即 aes(shape="mean")
  2. 创建手动形状比例,即 scale_shape_manual()

<块引用>

# 创建虚拟数据结果 <- data.frame(因子=因子(代表(1:10,100)),比例正=范数(1000))# 绘制结果ggplot(结果, aes(x=factor, y=proportionPositive)) +geom_boxplot() +stat_summary(fun.data = "mean_cl_normal",aes(shape="mean"),颜色 = "红色",geom="点") +scale_shape_manual("", values=c("mean"="x"))

How can I create a legend informing that the red cross is the mean?

ggplot(results, aes(x=factor, y=proportionPositive)) +
geom_boxplot() +
stat_summary(fun.data = "mean_cl_normal", colour = "red", shape=4)

解决方案

Here is one way of doing it:

  1. Map an aesthetic to a shape, i.e. aes(shape="mean")
  2. Create a manual shape scale, i.e. scale_shape_manual()

# Create dummy data
results <- data.frame(
  factor=factor(rep(1:10, 100)), 
  proportionPositive=rnorm(1000))

# Plot results
ggplot(results, aes(x=factor, y=proportionPositive)) +
      geom_boxplot() +
      stat_summary(fun.data = "mean_cl_normal", 
              aes(shape="mean"), 
              colour = "red",
              geom="point") +
      scale_shape_manual("", values=c("mean"="x"))

这篇关于stat_summary 的 ggplot2 图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆