Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphical parameters in ggplot2: How to change axis/tick thickness

Tags:

r

ggplot2

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

like image 337
godot Avatar asked Apr 07 '16 11:04

godot


People also ask

How do I change the axis thickness in ggplot2?

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.

How do you make an axis thicker in R?

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.

How do I change the number of ticks in ggplot2?

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)).

How do I change the scale of an axis in R?

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.


1 Answers

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()

like image 143
Prayag Gordy Avatar answered Oct 23 '22 20:10

Prayag Gordy