R 无法使用scale_x_离散向ggplot的x轴添加标签

R 无法使用scale_x_离散向ggplot的x轴添加标签,r,ggplot2,R,Ggplot2,由于某些原因,我无法将标签添加到ggplot的x轴。我使用的代码在过去是有效的,但在这种情况下有些东西不起作用 这是我的故事情节: RussetPlotMrk <-ggplot(mrkRus,aes(x=Rate,y=number)) + geom_bar(stat="identity", fill="#52854C") + theme_grey(base_size = 20) + facet_wrap(~Variety,nrow=2) + scale_x_discrete(la

由于某些原因,我无法将标签添加到ggplot的x轴。我使用的代码在过去是有效的,但在这种情况下有些东西不起作用

这是我的故事情节:


RussetPlotMrk <-ggplot(mrkRus,aes(x=Rate,y=number)) +
 geom_bar(stat="identity", fill="#52854C") +
 theme_grey(base_size = 20) +
 facet_wrap(~Variety,nrow=2) +
 scale_x_discrete(labels=c("125%", "100%", "75%", "50%", "75%50%")) +
 theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
 scale_y_continuous(breaks = seq(0,100,by = 10), limits=c(0, 100))

任何关于我做错了什么的想法都将不胜感激。提前感谢您的帮助

因为您的可变比率是连续(数字)值,所以您需要将其作为系数格式传递,以便使用
scale\u x\u discrete
设置标签:

库(ggplot2)
ggplot(df,aes(x=as.factor(Rate),y=number))+
几何图形栏(stat=“identity”,fill=“#52854C”)+
主题灰(基本尺寸=20)+
镶嵌面(种类,nrow=2)+
比例x离散(标签=c(“125%,“100%,“75%,“50%,“75%50%”)+
主题(axis.text.x=元素\文本(角度=45,hjust=1))+
刻度连续(断开=顺序(0100,比=10),极限=c(01000))

谢谢!我不知道为什么我没有注意到这不是一个因素。不客气!可能这取决于您如何加载数据集。。。有一个很好的延续;)
dput(head(mrkRus))
structure(list(Variety = structure(c(1L, 1L, 1L, 1L, 1L, 3L), .Label = c("Burbank 2018", 
"Burbank 2019", "Norkotah 2018", "Norkotah 2019", "Silverton 2018", 
"Silverton 2019"), class = "factor"), Rate = c(1L, 2L, 3L, 4L, 
5L, 1L), total = c(66.02375756, 62.50788744, 62.55239864, 69.73401417, 
66.30070975, 64.552774), mrktotal = c(43.49463647, 38.12657119, 
33.94832803, 44.94819267, 40.02596308, 49.07424897), per = structure(c(18L, 
16L, 14L, 17L, 15L, 22L), .Label = c("17%", "19%", "21%", "23%", 
"28%", "30%", "32%", "34%", "42%", "43%", "47%", "49%", "50%", 
"54%", "60%", "61%", "64%", "66%", "70%", "72%", "73%", "76%", 
"77%", "78%"), class = "factor"), number = c(66L, 61L, 54L, 64L, 
60L, 76L)), row.names = c(NA, 6L), class = "data.frame")