问题描述
在创建箱线图的过程中,我在y轴上有百分比.但是它显示为例如 20.0%
,而我更喜欢 20%
.有人知道该如何纠正吗?
box< -ggplot(boxy,aes(x = type,y = value))+geom_boxplot()+scale_y_continuous(labels = percent)+#我要固定轴的位置主题())
在这里找到答案:
正如您在此处阅读的?scale_y_continuous
一样,您可以提供一个以断点作为输入并以标签返回作为输出"的功能.输入中断( x
),添加%"
,输出标签.
In the process of creating a boxplot, I have percentages on the y-axis. However it shows up, for example, as 20.0%
and I would prefer 20%
. Does anybody know how to correct for this?
box<-ggplot(boxy,aes(x=type,y=value))+
geom_boxplot()+
scale_y_continuous(labels=percent)+ #where I am trying to fix the axis
theme()
)
The answer found here: How do I change the number of decimal places on axis labels in ggplot2? does not make sense to me because of the notation of the function itself. Also, it is less intuitive than declaring the number of decimals in the scale part of ggplot
Data:
type<-c(rep("One",10),rep("Two",10))
value<-c(91,15,55,7,2,19,72,8,52,61,93,48,20,44,33,84,80,88,26,23)
boxy<-data.frame(type,value)
In your case you can simply paste the "%"
ggplot(boxy,aes(x=type,y=value))+
geom_boxplot()+
scale_y_continuous(labels=function(x) paste0(x,"%"))
As you can read here ?scale_y_continuous
you can provide a function which "takes the breaks as input and returns labels as output". Input breaks (x
), add "%"
, output labels.
这篇关于R的百分比标签(不带小数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!