Continuous line chart

I have this dataframe

public <- data.frame(
  stringsAsFactors = FALSE,
                V1 = c(1L, 3L, 5L, 6L, 8L),
                V3 = c(2743L, 3397L, 3935L, 3993L, 4979L)
)

I do this to get a line chart:

ggplot(data = public) +
  aes(x = V1, y = V3, group = 1) +
  geom_line(color="grey", size=1.2, alpha=0.5)

I get this:

I'm trying to get the x-axis to show me only and exclusively 1, 3, 5, 6, 8, on a continuous basis, without showing intermediate steps. Something like this:

I hope it is clear what I want to do. Thanks all.

add this on the end

geom_line(color="grey", size=1.2, alpha=0.5)+
   scale_x_continuous(breaks=public$V1)
1 Like

Thanks nirgrahamuk, but with this solution I still have a blank space between 1 and 3, 3 and 5, 6 and 8, they don't follow the whole line as in the example or like between 5 and 6...maybe it can't be achieved with ggplot?

I'm afraid it's not clear what you want. The breaks you requested are arbitrary. Do you want the line chart distorted so that each break is equidistant to the other ? Seems an odd request but doable.... Or do you intend something else ?

ggplot(data = public) +
  aes(x = factor(V1), y = V3, group = 1) +
  geom_line(color="grey", size=1.2, alpha=0.5)

This is what I was looking for. Thanks nirgramuk.
Regards

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.