I just started using 'ggplot2', and am running into some problems with the graphical usability.
I wanted to do a simple regression biplot. However, I am not quite convinced by the themes offered by 'ggplot2' and 'ggthemes'.
My code thus far is as follows:
ggplot(data, aes(APE.15N, APE.13C)) +
geom_point(size=3) +
geom_smooth(method="lm", se=F, col="black") +
theme_light(base_size = 20) +
annotate("text", x=.9, y=1.35, label="R²=0.3192, p<0.001", size=6.5) +
coord_cartesian(xlim = c(.25, 1.1), ylim = c(1.05, 2.55)) +
ylab(expression(paste('APE '^{13}, "C", sep = ""))) +
xlab(expression(paste('APE '^{15}, "N", sep = "")))
...which gives me the following plot:
ouput from R with ggplot2
Now, I would like to increase the axis-line thickness as well as the tick thickness to at least 2 points, add minor ticks, get rid of the background grid, and change the axis colour to black.
I just can't figure out how...
I would imagine the result as in the following graph:
example graph
Thank you, your help is very much appreciated
To increase the width of axes (both X-axis and Y-axis at the same time) using ggplot2 in R, we can use theme function with axis. line argument where we can set element_line argument to a larger value.
To increase the width of the X-axis line for a ggplot2 graph in R, we can use theme function where we can set the axis. line. x. bottom argument size to desired size with element_line.
The default value of Y-axis tick marks using ggplot2 are taken by R using the provided data but we can set it by using scale_y_continuous function of ggplot2 package. For example, if we want to have values starting from 1 to 10 with a gap of 1 then we can use scale_y_continuous(breaks=seq(1,10,by=1)).
To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.
To increase the axis-line thickness and change the color to black:
axis.line = element_line(colour = 'black', size = 2)
To increase the tick thickness:
axis.ticks = element_line(colour = "black", size = 2)
To add minor ticks:
Minor ticks are not currently an option of ggplot2. There are many other stackoverflow questions about minor ticks that I would suggest looking at. You can try adding minor_breaks
in scale_x_continuous
, but that would require a knowing the actual minor ticks you want.
To remove the background grid:
panel.grid.major = element_blank()
, panel.grid.minor = element_blank()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With