I would like to visualize the following data in R in the form of a dot plot, with id number on the y-axis and date on the x-axis.
I used the following code:
ggplot(daily_activity_outliers, aes(x=date, y=id))
geom_point()
theme(axis.text.x=element_text(angle=90))
and received the following output:
I would like all the dates to appear on the x-axis, and also all 4 ids to appear on the y-axis (as is, and not chronologically) but I cannot find a way. The dataset looks as follows:
CodePudding user response:
Try passing the y axis (ids) as factor (or character).
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")
Created on 2022-10-28 with reprex v2.0.2