簡體   English   中英

geom_point ggplot2 中的數據點丟失/重疊

[英]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))

處理重疊/重合數據的兩種技術:

  1. 抖動點,使大多數重疊點移動一點;
  2. 將 alpha 應用於顏色,以便較暗的點表示更頻繁的數據。

數據

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 問題重疊

透明度(阿爾法)

ggplot(dat, aes(x, y)) +
  geom_point(color = "#00000022")

帶alpha的ggplot

抖動

ggplot(dat, aes(x, y)) +
  geom_point() +
  geom_jitter()

ggplot,抖動太多

這可能太多了,所以我們可以調整變化的程度。

ggplot(dat, aes(x, y)) +
  geom_point() +
  geom_jitter(width = 0.1, height = 0.1)

ggplot,減少抖動

阿爾法和抖動

這里不是嚴格要求的,但兩者都做可能有用:

ggplot(dat, aes(x, y)) +
  geom_point(color = "#00000022") +
  geom_jitter(width = 0.1, height = 0.1)

ggplot,抖動和阿爾法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM