Intellipaat Back

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

The y-axis title appears too close to the axis text.

ggplot(mpg, aes(cty, hwy)) + geom_point()

ggplot output

I have tried changing the value of many parameters with the theme() but none seems to help.

1 Answer

0 votes
by
edited by

You can use the margin argument of the element.text function to change the distance between the axis text and axis title.i.e.,

ggplot(mpg, aes(cty, hwy)) + geom_point()+

  theme(axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0)))

Set the values of the margin on top(t), right(r), bottom(b), and left(l) side of the element.

Output:

image

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...