您的问题只是您切换了y
变量:
# your code
ggplot(dataframe, aes(x = exit)) +
geom_point(aes(y = row.names(dataframe))) + # here y is the row names
geom_text(aes(y =exit, label = samplesize)) # here y is the exit column
由于您希望两者都具有相同的 y 值,因此您可以在初始ggplot()
调用中定义它,而不必担心以后重复
# working version
ggplot(dataframe, aes(x = exit, y = row.names(dataframe))) +
geom_point() +
geom_text(aes(label = samplesize))
使用行名有点脆弱,用你想要的 y 值实际创建一个数据列更安全、更健壮:
# nicer code
dataframe$y = row.names(dataframe)
ggplot(dataframe, aes(x = exit, y = y)) +
geom_point() +
geom_text(aes(label = samplesize))
完成此操作后,您可能不希望将标签放在点的顶部,也许稍微偏移会更好:
# best of all?
ggplot(dataframe, aes(x = exit, y = y)) +
geom_point() +
geom_text(aes(x = exit + .05, label = samplesize), vjust = 0)
在最后一种情况下,你必须调整x
审美,看起来正确的取决于你最终情节的尺寸