2

我有这个数据框

df <- structure(list(rang = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
      13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25.5, 25.5, 27.5, 
      27.5, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42.5, 
      42.5, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54.5, 54.5, 56, 
      57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 
      73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88
      ), dr = c(164, 176, 260, 297, 308, 313, 327, 333, 339, 365, 396, 
      403, 404, 410, 413, 414, 422, 424, 440, 442, 443, 451, 477, 496, 
      530, 530, 546, 546, 548, 565, 567, 574, 576, 587, 590, 603, 619, 
      626, 629, 630, 642, 653, 653, 660, 667, 670, 677, 682, 689, 711, 
      716, 737, 763, 772, 772, 776, 778, 792, 794, 820, 835, 838, 842, 
      855, 861, 888, 890, 899, 906, 908, 969, 1011, 1046, 1058, 1069, 
      1072, 1074, 1100, 1153, 1348, 1368, 1432, 1468, 1516, 1612, 1712, 
      1714, 1731), signe = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 
      2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 
      1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 
      1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
      2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 
      1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 
      2L), .Label = c("negatif", "positif"), class = "factor")), .Names = c("rang", 
      "dr", "signe"), row.names = c(NA, -88L), class = "data.frame")

stripchart当我使用基础 R 中的函数时,这张图表

stripchart(df[,1]~df[,3], 
       method="stack", vertical=FALSE, ylim=c(0.5,2.5), 
       group.names=levels(df[,3]), 
       xlab="Rang des différences dr", pch=18, cex=1.2)

我可以和图书馆有同样的情节ggplot2吗?我用过geom_dotplot,但我没有相同的情节。这是一个例子

ggplot(data = df, aes(y=df[,1], x=factor(df[,3]))) +
geom_dotplot(binaxis = "y", dotsize = 0.5) +
coord_cartesian(ylim=c(0, 88)) +
scale_y_continuous(breaks=seq(0, 88, 1))

请帮帮我!

4

2 回答 2

2

您必须翻转坐标,并设置binwidth = 1以获得相同的绘图:

ggplot(data = df, aes(y=rang, x=factor(signe))) +
  geom_dotplot(binaxis = "y", dotsize = 0.8, binwidth=1) +
  coord_cartesian(ylim=c(0, 88)) +
  scale_y_continuous(name='Rang des différences dr') +
  scale_x_discrete(name='') +
  coord_flip() + 
  theme_bw(base_size = 20)
于 2014-12-03T15:41:25.157 回答
1

这是否符合您正在寻找的内容:

ggplot(df) + geom_point(aes(df[,1],df[,3])) + theme_bw()
于 2014-12-03T15:37:53.950 回答