gpt4 book ai didi

r - 将渐变图例的比例更改为具有特定中断的百分比

转载 作者:行者123 更新时间:2023-12-04 10:52:35 24 4
gpt4 key购买 nike

我有一个带有渐变的热图,我想以特定百分比标记图例。

# example data, apologies for the kludginess 
library('ggplot2'); library('scales'); require('dplyr');
as.data.frame(with(mtcars, table(gear, cyl))) %>%
group_by(cyl) %>%
mutate(pct_of_cyl_class = Freq / sum(Freq)) %>%
ggplot(. ,aes(cyl, gear)) +
geom_tile(aes(fill=pct_of_cyl_class)) +
scale_fill_gradient(low='yellow',high='brown', name='% of Cyl. Group') +
geom_text(aes(label=percent(pct_of_cyl_class))) +
xlab('Cylinder Class') + ylab('Gears') +
ggtitle('Gear Frequency by Cylinder Class') + theme_minimal()

enter image description here

最佳答案

我需要设置 breakslabelsscale_fill_gradient() .

+ scale_fill_gradient(low='yellow',high='brown', 
name='% of Cyl. Group',
breaks = 0.25*0:4, labels = percent(0.25*0:4) ) # <-

enter image description here

关于r - 将渐变图例的比例更改为具有特定中断的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33532738/

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