我正试图在R中设计一个相当自定义的情节。
我想做的一件事是添加与标签不同的刻度线 - 也就是说,只会标记每5个刻度线。我没有看到一个简单的方法,所以我这样做了:
plot(x = Freq_, y = Mean_ipsi,
pch = 20,
ylim = c(-0.5, .9),
col = 1 + (ProbF < .05) + (ProbF < .01),
xaxt = 'n',
xlab = "Frequency (MHz)", ylab = "z-in minus z-out",
main = "Temporal, Engle 1, Epi, subjectwise",
yaxt = 'n')
mtext(text = seq(1.56, 35.1, by = 1.95),
side = 1, at = seq(1.56, 35.1, by = 1.95), cex = .5,line = 0.25)
axis(1, at = Freq_, tick = TRUE, labels = NA)
它就像我想要的那样工作。
但是当我改变mtext之前的一些代码时,我得到了意想不到的结果
plot(x = Freq_, y = Mean_ipsi,
pch = 20,
ylim = c(-0.5, .9),
col = "red",
xlab = "Frequency (MHz)", ylab = "z-in minus z-out",
main = "Temporal, Engle 1, Epi, subjectwise
\n p values for difference between ipsi and contra",
yaxt = 'n', type = 'o')
mtext(text = seq(1.56, 35.1, by = 1.95),
side = 1, at = seq(1.56, 35.1, by = 1.95),
cex = .5,line = 0.25)
axis(1, at = Freq_, tick = TRUE, labels = NA)
现在,除了x轴标有每个数字1.56,3.51等之外,我得到大数(cex = 1,我认为)在5,10等等。我不想要这些。
我不知道这里发生了什么。
答案 0 :(得分:4)
你的第二个版本中缺少xaxt="n"
。
Freq_ <- seq(1.56, 35.1, by = 1.95)
Mean_ipsi <- (0.01 * Freq_)
ProbF <- 0.0
#First Version
plot(x = Freq_, y = Mean_ipsi,
pch = 20,
ylim = c(-0.5, .9),
col = 1 + (ProbF < .05) + (ProbF < .01),
xaxt = 'n',
xlab = "Frequency (MHz)", ylab = "z-in minus z-out",
main = "Temporal, Engle 1, Epi, subjectwise",
yaxt = 'n')
mtext(text = seq(1.56, 35.1, by = 1.95),
side = 1, at = seq(1.56, 35.1, by = 1.95), cex = .5,line = 0.25)
axis(1, at = Freq_, tick = TRUE, labels = NA)
#=============================================
#Second Version
plot(x = Freq_, y = Mean_ipsi,
pch = 20,
ylim = c(-0.5, .9),
col = "red",
xlab = "Frequency (MHz)", ylab = "z-in minus z-out",
main = "Temporal, Engle 1, Epi, subjectwise
\n p values for difference between ipsi and contra",
yaxt = 'n', type = 'o') ##### <----- add xaxt="n" here #####
mtext(text = seq(1.56, 35.1, by = 1.95),
side = 1, at = seq(1.56, 35.1, by = 1.95),
cex = .5,line = 0.25)
axis(1, at = Freq_, tick = TRUE, labels = NA)