【问题标题】:Change title legend when use ggplot2 stat_sum使用 ggplot2 stat_sum 时更改标题图例
【发布时间】:2014-09-26 10:00:42
【问题描述】:

我想更改使用stat_sum 构建的ggplot2 图表的标题图例。 这里stat_sum不要使用比例而是使用总和。

数据:

data <- structure(list(replicate = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 
1L, 2L, 3L, 1L, 2L, 3L), .Label = c("A", "B", "C"), class = "factor"), 
conc = c(0, 0, 0, 0.074, 0.074, 0.074, 0.22, 0.22, 0.22, 
0.66, 0.66, 0.66), time = c(21L, 21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L), Nsurv = c(18L, 19L, 19L, 19L, 
19L, 18L, 16L, 16L, 18L, 3L, 3L, 3L), Nrepro = c(161L, 102L, 
128L, 151L, 73L, 60L, 98L, 52L, 123L, 0L, 5L, 0L), conc2 = c(0, 
0, 0, 0.074, 0.074, 0.074, 0.22, 0.22, 0.22, 0.66, 0.66, 
0.66)), .Names = c("replicate", "conc", "time", "Nsurv", 
"Nrepro", "conc2"), row.names = c(43L, 44L, 45L, 88L, 89L, 90L, 
133L, 134L, 135L, 178L, 179L, 180L), class = "data.frame")

我使用以下方法创建ggplotobject:

sp <- ggplot(data,aes(conc2, Nsurv)) +
stat_sum(aes(size = factor(..n..))) +
labs(x = "concentration",
y = "response")

我尝试了不同的函数来更改标题图例但没有结果:

sp + guides(fill=guide_legend(title = "points")) #no change
#or
sp + guides(color=guide_legend(title = "points")) #no change
sp + scale_fill_discrete(name = "points") #no change
#or
sp + guide_legend(title="points") #don't work
#or
sp + scale_colour_brewer(name = "points") #no change
#or
sp + scale_colour_hue("points") #no change

有什么想法吗?

【问题讨论】:

    标签: r ggplot2 legend


    【解决方案1】:

    您正在尝试更改因子的大小比例的名称。因此您需要将参数传递给scale_size_discrete

    sp <- ggplot(data,aes(conc2, Nsurv)) +
      stat_sum(aes(size = factor(..n..))) +
      labs(x = "concentration",
           y = "response") +
      scale_size_discrete(name = "points")
    

    【讨论】:

      猜你喜欢
      • 2019-03-29
      • 2015-07-11
      • 2021-01-02
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 2015-09-20
      • 2015-03-30
      相关资源
      最近更新 更多