如何在ggplot2中绘制所有点?

时间:2017-05-03 02:29:19

标签: r plot ggplot2

我有一个数据框df,想制作一个点图。 我无法将所有值绘制(或显示)为点,; 20分中只显示了8分。我认为,这是因为Lat和Lon的重叠? 有没有办法可以显示所有绘制的值,即20点而不仅仅是8? 谢谢。enter image description here

dput(df)
structure(list(Lat = c(55.5, 49.5, 49.5, 60, 58.5, 55.5, 54, 
49.5, 55.5, 52.5, 58.5, 55.5, 55.5, 55.5, 55.5, 52.5, 55.5, 49.5, 
49.5, 48, 58.5), Lon = c(-132, -126, -124.5, -139.5, -136.5, 
-132, -129, -126, -132, -127.5, -136.5, -132, -132, -132, -132, 
-127.5, -132, -126, -126, -123, -136.5), Value = c(169, 308, 
178, 110, 224, 280, 212, 365, 224, 276, 121, 159, 166, 342, 96, 
283, 51, 375, 198, 284, 201)), .Names = c("Lat", "Lon", "Value"
), row.names = c(168969L, 169011L, 169123L, 169285L, 169570L, 
169611L, 169858L, 169905L, 170237L, 170263L, 170483L, 170496L, 
170666L, 170684L, 170815L, 170834L, 170893L, 170916L, 171073L, 
171093L, 171201L), class = "data.frame")

p <- ggplot() +
    geom_point(data = df,aes(x = Lon, y = Lat, colour = Value))
p

2 个答案:

答案 0 :(得分:5)

他们确实是重叠的。尝试使用position_jitter。使用widthheight进行更好的控制。

library(ggplot2)

ggplot() + geom_point(data = df,aes(x = Lon, y = Lat, colour = Value),
position=position_jitter(width=1,height=.1))

enter image description here

答案 1 :(得分:2)


library(ggplot2)

ggplot(data = df,aes(x = Lon, y = Lat, colour = Value)) +
  geom_jitter()