gpt4 book ai didi

r - 在 ggplot 中编辑图例标签

转载 作者:行者123 更新时间:2023-12-04 11:59:32 27 4
gpt4 key购买 nike

我有一个如下所示的数据框:

data
median min max no_of_threads
2.33 2.10 6.85 1
2.43 2.14 3.41 2
2.39 2.13 7.90 3
2.74 2.10 8.30 4
2.53 2.21 6.69 5

我制作了这个 R 函数,它将 data$min 和 data$max 绘制为范围,将 data$median 绘制为线:

scalability_graph <- function(data){ 
h <- ggplot(data)
h <- h +
geom_ribbon(aes(x = no_of_threads, ymin = min, ymax = max)) +
geom_line(aes(x = no_of_threads, y=median, color="#CC873D")) +
scale_x_continuous("Number of threads", lim=c(0,20)) +
scale_y_continuous("Response time", lim=c(0,13)) +
opts(legend.position=c(0.20,0.90))
}

脚本产生了这个情节:

range graph with median

如何更改图例中的标签并使用“范围”代替顶部粗体字符串,使用“中值”代替底部标签?

最佳答案

你可以通过添加这个来做到这一点:

 + scale_colour_manual("range", labels = "median", values = "#CC873D", breaks = "#CC873D") 

enter image description here

但是你的剧情和传说应该是这样的?

h <- ggplot(data, aes(no_of_threads, median)) +
geom_ribbon(aes(ymin = min, ymax = max, fill = factor(1))) +
geom_line(aes(color=factor(1))) +
scale_x_continuous("Number of threads", lim=c(0,20)) +
scale_y_continuous("Response time", lim=c(0,13)) +
scale_fill_manual(breaks = 1, values = "grey20", labels = "range") +
scale_colour_manual(breaks = 1, values = "#CC873D", labels = "median") +
opts(legend.position=c(0.20,0.85), legend.title = theme_blank(), legend.background = theme_blank())

enter image description here

关于r - 在 ggplot 中编辑图例标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7899454/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com