[英]Data point missing/overlapping in geom_point ggplot2
我的數據集中有大約 900 個數據點,但是在我繪制之后,圖中的數據圖看起來不到 100,這是因為重疊嗎? 或其他一些原因,我不確定。
這是我的情節:
我的代碼
ggplot(data, aes(x = as.numeric(`x1`), y=`x2`, color=`x3`)) +
geom_point() +
scale_x_continuous(breaks = seq(0,135,15))
處理重疊/重合數據的兩種技術:
set.seed(42)
dat <- data.frame(
x = round(rnorm(100), 0),
y = round(rnorm(100), 0)
)
head(dat)
# x y
# 1 1 1
# 2 -1 1
# 3 0 -1
# 4 1 2
# 5 0 -1
# 6 0 0
xtabs(~ x + y, data=dat)
# y
# x -2 -1 0 1 2 3
# -3 0 1 0 0 0 1
# -2 1 3 1 0 0 0
# -1 1 1 11 7 1 0
# 0 1 13 13 8 1 0
# 1 2 6 17 4 1 0
# 2 0 0 5 1 0 0
library(ggplot2)
ggplot(dat, aes(x, y)) + geom_point()
ggplot(dat, aes(x, y)) +
geom_point(color = "#00000022")
ggplot(dat, aes(x, y)) +
geom_point() +
geom_jitter()
這可能太多了,所以我們可以調整變化的程度。
ggplot(dat, aes(x, y)) +
geom_point() +
geom_jitter(width = 0.1, height = 0.1)
這里不是嚴格要求的,但兩者都做可能有用:
ggplot(dat, aes(x, y)) +
geom_point(color = "#00000022") +
geom_jitter(width = 0.1, height = 0.1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.