R 如何创建具有yaxis字符和多个x值的绘图?多点克利夫兰点图?

R 如何创建具有yaxis字符和多个x值的绘图?多点克利夫兰点图?,r,plot,ggplot2,yaxis,R,Plot,Ggplot2,Yaxis,我试图用一个字符/因子yaxis和R中x的多个值来绘制一个图 基本上:下图旋转了90度: df <- data.frame(A = c(2,3,5,5,2), B = c(1,2,6,6,5)) rownames(df) <- c("02", "07", "08", "12", "99") matplot(df, pch="x", xaxt = "n") axis(side=1,at=1:nrow(df), labels = rownames(df)) 我是否正确怀疑matplot

我试图用一个字符/因子yaxis和R中x的多个值来绘制一个图

基本上:下图旋转了90度:

df <- data.frame(A = c(2,3,5,5,2), B = c(1,2,6,6,5))
rownames(df) <- c("02", "07", "08", "12", "99")
matplot(df, pch="x", xaxt = "n")
axis(side=1,at=1:nrow(df), labels = rownames(df))
我是否正确怀疑matplot无法接受yaxis的字符/因子输入

我也尝试过ggplot,但我无法给它x的多个值。另外,我更喜欢不单独添加数据的解决方案,因为我的原始数据中每个观察值至少有15个值

ggplot(df, aes(x=df$A, y=rownames(df))) + geom_point(data = df$B)
也许我错过了一个显而易见的解决方案

一些我还不知道的包裹

谢谢大家!

对于ggplot,您可以为数据集中的每列绘制一个单独的
geom_点
层(即一个表示“a”,一个表示“B”),但将数据帧转换为长格式和使用ggplot的美学映射更为简洁:

df$rowname <- rownames(df)
rownames(df) <- NULL

ggplot(melt(df), #convert from wide to long format
        aes(x = rowname, y = value, group = variable, colour = variable)) +
  geom_point(size = 3) +
  xlab("") + ylab("") + theme_classic() +
  coord_flip()
df$rowname
df$rowname <- rownames(df)
rownames(df) <- NULL

ggplot(melt(df), #convert from wide to long format
        aes(x = rowname, y = value, group = variable, colour = variable)) +
  geom_point(size = 3) +
  xlab("") + ylab("") + theme_classic() +
  coord_flip()