我有一个带有渐变的热图,我想以特定百分比标记图例。
# 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()
Run Code Online (Sandbox Code Playgroud)
我需要设置breaks和labels在scale_fill_gradient()。
+ scale_fill_gradient(low='yellow',high='brown',
name='% of Cyl. Group',
breaks = 0.25*0:4, labels = percent(0.25*0:4) ) # <-
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3197 次 |
| 最近记录: |