我在R中有一个简单的哑铃图,我希望我的y轴将值绘制为文本。由于我的y轴值默认情况下是数字,因此将其视为数字,但我需要将其显示为文本。从我的示例here中可以看到,该图不太正确。
library(ggplot2)
library(ggalt)
df <- data.frame(trt=c(11111,22222,33333,44444,55555), l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, 80))
ggplot(df, aes(y=trt, x=l, xend=r)) +
geom_dumbbell(size=3, color="#e3e2e1",
colour_x = "#5b8124", colour_xend = "#bad744",
dot_guide=TRUE, dot_guide_size=0.25) +
labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") +
theme_minimal() +
theme(panel.grid.major.x=element_line(size=0.05)) +
theme(panel.grid.major.y=element_blank())
想想我自己对这个排序了。现在,将“因子”添加到y轴变量中会将其显示为类别,而不是数字。
所以我的ggplot函数的顶部现在显示为:ggplot(df, aes(y=factor(trt), x=l, xend=r))