Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I am having a simple plot. I log scaled the x-axis and I need the graph to show 0.1, 1, 10. I can't estimate out how to override the default of 0.1, 1.0, 10.0.

Is there a way I could change only two of the x-axis labels?

library(ggplot2)

x <- c(0.1, 1, 10)

y <- c(1, 5, 10)

ggplot()+

  geom_point(aes(x,y)) +

  scale_x_log10()

enter image description here 

1 Answer

0 votes
by (107k points)

You could define the labels and breaks in scale_x_log10():

library(ggplot2)

x <- c(0.1, 1, 10)

y <- c(1, 5, 10)

ggplot() + geom_point(aes(x,y)) + scale_x_log10(labels = x, breaks = x)

enter image description here

If you are a beginner and want to know more about R then do check out the R programming course.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...