How do I specify axis thickness in a plot? (in R)
Asked Answered
C

5

12

I am using using plot(), matplot() and ggplot(). I am guessing the answer will be the same for all of them.

I want to specify the thickness of the y-axis, the x-axis, and the other two lines that constitute the box around the plot, all separately. How can I achieve that?

Thanks in advance.

Note: I have already read this - Increasing the thickness of box lines in an R boxplot? , but I want to change the thickness of the individual axis lines separately.

Ceruse answered 2/5, 2013 at 10:20 Comment(0)
C
14

You mean list this?

plot(sample(100))

axis(side = 1, lwd = 2)
axis(side = 2, lwd = 2)

enter image description here

Comte answered 2/5, 2013 at 10:25 Comment(1)
This will look better if you in addition do box(lwd=2).Ritualism
L
1

See ?axis and use it along with plot(). Here is a nice tutorial.

Leahy answered 2/5, 2013 at 10:25 Comment(0)
G
1

Well, I could make it by using the command at = x and describing the distance from 0 to the end of the axis, either by your desired scale, counts or length (I just have no clue whether the length is in inches, cm, etc. I tried numbers until I got the right lenght). Hope it helps!

One thing I did not manage was to input breaks to the axis 2, so I had to type the whole scale. As I have lots of plots which differs in scales, this will become boring at some stage. Any idea how to break scales using "axis" command?

Cheers, Romário

axis(1, at = 0:15, lwd=2, lwd.tick=0, lab=F)
axis(2, at = c(0, 2000, 4000, 6000, 8000, 10000, 12000), lab=c(0, 2000, 4000, 6000, 8000, 10000, 12000), lwd=2, lwd.tick=1, tck=0.01, las=1, cex=0.5)

PS: Couldn't post the final plot. I need at least 10 reputation to post images.

Galle answered 23/5, 2014 at 9:39 Comment(0)
K
0

For ggplot use the following as a statement in the ggplot set of comments with + before and maybe after depending on what else you need. This is for the x-axis, and the equivalent is axis.line.y.left= for the y-axis.

theme(axis.line.x.bottom=element_line(size=1))

Kelwunn answered 21/4, 2023 at 11:21 Comment(0)
M
0

Just a note on previous posts, you use linewidth=1 not size=1 in ggplot2, currently. So your plot would have something like

ggplot(aes(x,f),data=df)+geom_point()+ theme(axis.line.x.bottom=element_line(linewidth=1), axis.line.y.left=element_line(linewidth=1))

Micronesian answered 4/2 at 18:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.