简体   繁体   English

scale_color_gradient2具有四舍五入的文本

[英]scale_color_gradient2 having text be rounded

I am using scale_fill_gradient2() and the colourbar that is created is showing decimal places. 我正在使用scale_fill_gradient2()并且创建的颜色栏显示小数位。 I tried to reproduce the text that shows decimals but could not but the text below is in scientific notations. 我试图重现显示小数的文本,但不能重现,但以下文本采用科学计数法。

How can you round the numbers that displayed in the colourbar using scale_fill_gradient2() ? 如何使用scale_fill_gradient2()对颜色scale_fill_gradient2()显示的数字取整? For example I am seeing "25.00" and I'd like to show just "25"? 例如,我看到的是“ 25.00”,而我只想显示“ 25”?

Also how can you set the labels manually? 另外,如何手动设置标签? Let's say I want to look a the data and set labels like c(15, 25, 40) ? 假设我要查看数据并设置类似c(15, 25, 40)标签?

library(ggplot2)
dat <- data.frame(group = c(rep("A", 10), rep("B", 10)),
                  value = c(rnorm(10, 5,300), rnorm(10, 5000, 80000)))

ggplot(dat, aes(x = group, y = value, fill= value)) + 
       geom_bar(stat = "identity") +
       scale_fill_gradient2(low = "red", mid = "yellow", high = "blue", midpoint = 0, name = "")

You can manually specify breaks and labels as needed. 您可以根据需要手动指定中断和标签。

ggplot(dat, aes(x = group, y = value, fill= value)) +
  geom_bar(stat = "identity")+
  scale_fill_gradient2(low = "red", mid = "yellow", high = "blue", 
                       midpoint = 0, name = "",
                       breaks = c(0, 1e5, 2e5),
                       labels = c("0", "100,000", "200,000"))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM