我想以點圖的形式可視化 R 中的以下資料,y 軸為 id 編號,x 軸為日期。
我使用了以下代碼:
ggplot(daily_activity_outliers, aes(x=date, y=id))
geom_point()
theme(axis.text.x=element_text(angle=90))
并收到以下輸出:

我希望所有日期都出現在 x 軸上,并且所有 4 個 id 都出現在 y 軸上(按原樣,而不是按時間順序),但我找不到方法。資料集如下所示:

uj5u.com熱心網友回復:
嘗試將 y 軸(ids)作為因子(或字符)傳遞。
library(ggplot2)
df <-
data.frame(id = c(2347167796, 2347167796, 2347167796, 2347167796,
2347167796, 2347167796, 2347167796, 2347167796, 2347167796, 3372868164,
3372868164, 3372868164, 3372868164, 3372868164, 3372868164, 3372868164,
3372868164, 3372868164, 3372868164, 4057192912, 4057192912, 4057192912,
4057192912, 8253242879, 8253242879),
date = structure(
c(16903, 16904, 16905, 16906, 16907, 16908, 16909, 16910, 16911, 16903,
16904, 16905, 16906, 16907, 16908, 16909, 16910, 16911, 16912,
16903, 16904, 16905, 16906, 16903, 16904),
class = "Date"))
ggplot(data = df,
aes(x = date,
y = as.factor(id)))
geom_point()
labs(y = "id")

使用 reprex v2.0.2 創建于 2022-10-28
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/522755.html
標籤:rggplot2
