Vibramat
Vibramat

Reputation: 217

Show the x value on the x-axis for each point in a ggplot

I have a ggplot with some points and I would like to show all the x values on the x-axis.

day = c(1,2,3,4,5,6,7,8,9,10)
value =c(4.63, 3.58, 3.52, 4.42, 4.09, 3.51, 3.95, 4.51, 3.45 ,1.76)
data <- tibble(day, value)

data %>% ggplot(aes(day,value)) + geom_point()

enter image description here

So instead of showing: 2.5,5.0,7.5,10 I would like to display all values between 1 and 10.

How can I do this?

Upvotes: 1

Views: 2353

Answers (1)

TarJae
TarJae

Reputation: 78947

Make your x axis as.factor

day = as.factor(c(1,2,3,4,5,6,7,8,9,10))
value =c(4.63, 3.58, 3.52, 4.42, 4.09, 3.51, 3.95, 4.51, 3.45 ,1.76)
data <- tibble(day, value)

data %>% ggplot(aes(day,value)) + geom_point()

enter image description here

Upvotes: 2

Related Questions