I have a data frame that is only a single column of values 1-100 each. I want to plot these (using geom_point) such that y = the values in the column, and x is just the order of the values in the column (i.e. for the first value in the column, x = 1, second value x = 2, etc.). I could mutate in another column called index that just adds an index number for each observation, but is there a way to do it without doing that? Like, if I want to leave the data intact as just one column?
I believe setting x = 1:nrow(df)
produces your desired outcome.
library(tidyverse)
set.seed(44)
df = data.frame(A = sample(1:100, 100, TRUE))
ggplot(df, aes(x = 1:nrow(df), y = A)) +
geom_point()
Created on 2022-10-28 with reprex v2.0.2.9000
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.