简体   繁体   English

在 R 中的 ggballoonplot() 的图例上显示仅整数值

[英]Displaying integer-only values on the legend of a ggballoonplot() in R

I have the following data:我有以下数据:

my_data <- read.table(text = 

"Name  Make  Count
Rex  BMW  4
Uma  Mercedes  3
Mike  Mercedes  3
Carol  Mercedes  3
Carol BMW  3
Jason  Audi  2
Gary  Audi  2
Stephanie  Mercedes  2
Moses  Mercedes  2
Cary  Mercedes  2
Allen  Mercedes  2
Harry  Honda  2
Deg  Honda  2
Carol  Honda  2", header=TRUE)

I'm interested in generating a Balloon Plot to display the relative impact of User and Make.我有兴趣生成气球 Plot 以显示用户和制造的相对影响。 The code I'm using to do so is as follows:我用来这样做的代码如下:

ggballoonplot(my_data, x='Make', y='Name', fill='Count', shape = 21, sorted=FALSE) +
  gradient_fill(c('green', 'yellow', 'orange', 'red'))

Checking the documentation at https://www.rdocumentation.org/packages/ggpubr/versions/0.2.5/topics/ggballoonplot , I don't see any options that would prevent the legend from displaying non-integer values.检查https://www.rdocumentation.org/packages/ggpubr/versions/0.2.5/topics/ggballoonplot上的文档,我没有看到任何会阻止图例显示非整数值的选项。

Is it possible to display integer-only values on the legend of a ggballoonplot?是否可以在 ggballoonplot 的图例上显示仅整数值?

As ggballoonplot is based on ggplot2 , you can use scale_fill_gradientn and scale_size to set appropriate values and breaks to display only integer values:由于ggballoonplot基于ggplot2 ,您可以使用scale_fill_gradientnscale_size设置适当的值和中断以仅显示 integer 值:

ggballoonplot(my_data, x='Make', y='Name', fill='Count', shape = 21, sorted=FALSE)+
  scale_fill_gradientn(colours =  c('green', 'yellow', 'orange', 'red'), breaks = c(2,3,4))+
  scale_size(range = c(1,10), breaks =c(2,3,4))

在此处输入图像描述

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

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