Open AshtonHop9 opened 3 years ago
What graphics package are you using?
@jamisoncrawford I didn’t load a graphics package like ggplot2, so I think that means I am just using the standard R graphics package.
What are you currently doing? Some code and current image would be helpful.
@lecy Currently I am replicating a NYT graph about baseball strikeout averages, here is some of my beginning code..
plot.new()
par(mar=c(5.1, 4.1, 4.1, 3.1), xpd=TRUE)
plot.window(xlim = c(1900, 2012), # Specify x-axis limits ylim = c(ave.so.min, ave.so.max), xaxs = "i") # Specify y-axis limits
points(x = year, y = ave.so, col = "gray90", xpd = NA, # Color pch = 16, # Shape cex = 0.8) # Size
axis(side = 1, #X axis style
at = seq(from = 1900,
to = 2020,
by = 10),
xlim = c(1900, 2020),
mgp = c(3,0,0),
tcl = -0.2, # Size of the tick mark labels
cex.axis = 0.7,
xpd = FALSE)
axis(side = 4, las = 1, # Y axis Style at = c(0,1,2,3,4,5,6,7,9), cex.axis = 0.7, mgp = c(0,1,0), #location of axis labels tick = 0, # Eliminates Tick Line col.axis = "gray75") # Color to be used for tick mark labels
I am trying to shift the x axis values slightly to the right so they are not centered with the ticks.
Try:
axis( … , hadj=2 ) # might be padj
These let you move text around their default placement. Should accept positive and negative values. Zero is probably default.
@AshtonHop9 check out the documentation of axis()
by typing ?axis
. There is an argument listed that will adjust axis labels horizontally (h) or vertically (v).
@lecy just beat me to it!
There’s a similar argument for the text() function, slightly different syntax.
adj=c(0.5,0.5)
one or two values in \([0, 1]\) which specify the x
(and optionally y) adjustment (‘justification’) of
the labels, with 0 for left/bottom, 1 for right/top,
and 0.5 for centered. On most devices values
outside \([0, 1]\) will also work.
Both use adj for adjust but axis() has two arguments while text() has one with two values.
One downside of having lots of people contributing functions - tiny inconsistencies in syntax that are frustrating when you are learning.
After awhile they become charming, but it takes some time :-)
One more power tip. Type this to get all of the default graphical parameters:
par()
@jamisoncrawford @lecy
Thanks! It worked! Also, thanks for the pro tip and additional information. You guys are the real MVPs!
Hey everyone,
I have been looking forever for how to shift my labels on the X axis to the right and I cannot find anything! If anyone could point me in the right direction I would really appreciate it!!
Thanks!