Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R How can I emphasize the x axis using ggplot?

Tags:

r

ggplot2

axis

If I use ggplot, then the horizontal line for the x axis (y==0) is the same as any other value for y. I'd like to highlight the fact that the bottom of the graph is NOT the x axis, and that the x axis is higher in the plot. How can I do this?

data.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8))

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5)
like image 647
JoeBass Avatar asked Dec 20 '22 04:12

JoeBass


2 Answers

You could highlight the axes with black lines

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) +
geom_point(size = 5) +
geom_hline(aes(yintercept = 0)) +
geom_vline(aes(xintercept = 0))
like image 179
blakeoft Avatar answered Jan 03 '23 22:01

blakeoft


you can also change the colour and width of the axes directly by adding e.g.:

+ theme(axis.line = element_line(colour = 'red', size = 2))
like image 36
erc Avatar answered Jan 03 '23 20:01

erc