How to adjust the vertical space between labels as well as data points within my plot?
Some example data:
data <- data.frame(
a = c(-2.5, -1.2, 0, 1.4, 2.8),
b = c("Var1", "Var2", "Var3", "Var4", "Var5")
)
plot(
data$a,
seq_along(data$a),
xaxt = "n",
yaxt = "n"
)
axis(2, at = seq_along(data$b), labels = data$b, las = 2)
which produces:
I have no clue how to adjust this.
You have categorical y variables, so your y axis values are 1,2,3,4,5
. So you could shrink the distance artificially by multiplying by 0.5 (at = seq_along(data$b)*0.5
) but the visual would look the same because the y axis limits would just automatically adjust.
I think what you want to do is save the plot using different aspect ratios. For example:
jpeg(filename = 'junk.jpg', res = 800,
height = 7, width = 12, units = 'in')
plot(
data$a,
seq_along(data$a),
xaxt = "n",
yaxt = "n"
)
axis(2, at = seq_along(data$b), labels = data$b, las = 2)
dev.off()
AND:
jpeg(filename = 'junk.jpeg', res = 800,
height = 4, width = 8, units = 'in') # Change vertical size
plot(
data$a,
seq_along(data$a),
xaxt = "n",
yaxt = "n"
)
axis(2, at = seq_along(data$b), labels = data$b, las = 2)
dev.off()
hope that helps!