自定义轴标签 [英] Customize axis labels
本文介绍了自定义轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的 geom_point
图,其中 x
变量是序数,取5个值(编码为1 :5)。
在图中,我想用5个相应的文本标签替换它。是否可以在ggplot中完成?
解决方案
您应该可以通过 scale_x_discrete
。
library(ggplot2)
df< - data.frame(x = 1 :5,y = sample(1:10,5,TRUE))
qplot(factor(x),y,data = df)+
scale_x_discrete(breaks = 1:5,标签= c(foo,bar,baz,phi,fum))+
xlab(NULL)
I have a simple geom_point
plot, in which the x
variable is ordinal, taking 5 values (coded 1:5).
In the plot I would like to replace it with 5 corresponding text labels. Is it possible to do it in ggplot?
解决方案
You should be able to do this with scale_x_discrete
.
library(ggplot2)
df <- data.frame(x = 1:5, y = sample(1:10, 5, TRUE))
qplot(factor(x),y, data = df) +
scale_x_discrete(breaks = 1:5, labels=c("foo","bar","baz","phi","fum")) +
xlab(NULL)
这篇关于自定义轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文