plot - R: Suppress ticks and labels at endpoints of axis -
i have code producing below pasted plot
x <- c(2, 3, 4) y <- c(2.5, 4.1, 5.5) plot(x, y, type = "o", xlim = c(1, 5), ylim = c(2, 6), axes = false, bty = "n") axis(side = 1, @ = seq(1, 5, 1)) axis(side = 2, @ = seq(2, 6, 1), las = 2)
i have neither ticks nor labels @ position 1 , 5, axis should still drawn. looking for:
when using labels = c("", 2, 3, 4, "")
ticks drawn. when using tick = false
, no axis. have solution this?
you need draw line manually. using line2user
function in this answer:
x <- c(2, 3, 4) y <- c(2.5, 4.1, 5.5) plot(x, y, type = "o", xlim = c(1, 5), ylim = c(2, 6), axes = false, bty = "n") axis(side = 1, @ = 2:4) lines(x = c(1, 5), y = rep(line2user(0, side = 1), 2), xpd = true) axis(side = 2, @ = seq(2, 6, 1), las = 2)
note, line2user
function gives position of lines in user coordinate system. need xpd = true
draw outside plotting region.
Comments
Post a Comment