Defining the axis values in an R plot
I know this seems trivial, but for some reason I´m stuck and I cannot figure out how to solve it. I have checked for the solution but with no success.
My data ("coefs_PA") is like this
structure(list(year = c(1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
2015, 2016, 2017, 2018, 2019), estimate = c(0.111, 0.081, -0.106,
2.571, 0.606, -0.234, 0.325, 0.891, 0.062, 0.37, -0.041, 0.09,
0.436, 0.08, -0.973, 0.147, -0.116, 0.602, 0.385, 0.274, 0.118,
0.682), sd = c(0, 0.488, 0.411, 1.282, 0.473, 0.447, 0.427, 0.52,
0.477, 0.394, 0.384, 0.379, 0.404, 0.416, 0.43, 0.419, 0.464,
0.788, 0.456, 0.451, 0.427, 0.467)), row.names = c(NA, -22L), class = "data.frame")
and with the following code
library(Hmisc)
plot(coefs_PA$year, coefs_PA$estimate, xaxt='n', yaxt="n", xlab=NA, ylab=NA, pch=17,
ylim=c(min(coefs_PA$estimate - coefs_PA$sd), max((coefs_PA$estimate + coefs_PA$sd))))
with (data = coefs_PA, expr = errbar(year,estimate, estimate+sd, estimate-sd, add=T, cap=0))
axis(2, las=2, at = c(-1:4, 1))
minor.tick(nx = 0, ny = 2, tick.ratio = 0.7)
axis(1, at=coefs_PA$fecha)
title(ylab=expression("Logit (P"[p]*")"), line=1.6, cex.lab=1)
mtext(side=3, line=0.2, "Year", font=2, cex=1.0)
I get the following figure
I want the values of the x-axis to be 2000, 2005, 2010, 2015 and the remaining tick marks to be blank. I have tried to get it with this
axis(1, at=coefs_fechas_PA$fecha, labels= c(rep("",2), "2000", rep("",4), "2005", rep("",4), "2010", rep("",4), "2015", rep("",4))))
but it didn´t work.
Any hint will be more than welcome.
from Recent Questions - Stack Overflow https://ift.tt/377nZ9u
https://ift.tt/3rQv5sv
Comments
Post a Comment