R 如何在ggplot2中的轴标签下方添加线?

R 如何在ggplot2中的轴标签下方添加线?,r,R,如何在轴标签下方添加一条线,就像附件中50100和200轴标签下方有一条线一样? 示例(不包含GGPLOT2): data("mtcars") counts <- table(mtcars$gear) barplot(counts, main="Car Distribution", xlab="Number of Gears") axis(1, # Put 1 for X-axis, 2 for Y-axis at=c(0, 5), #Limit of line

如何在轴标签下方添加一条线,就像附件中50100和200轴标签下方有一条线一样? 示例(不包含GGPLOT2)

data("mtcars")
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution", 
        xlab="Number of Gears")
axis(1, # Put 1 for X-axis, 2 for Y-axis
     at=c(0, 5), #Limit of line
     col="red", 
     line=2.5, # how much gap you need between line and X-axis
     labels=rep("",2), # remove line labels
     lwd=2,
     lwd.ticks=0) # remove ticks

也许
ggplot2
中的
facet\u wrap
是一个起点:

库(magrittr)
图书馆(GG2)
mtcars%>%

dplyr::mutate(hp_200=ifelse(hp>200,“hp>200”,“hp I得到这个错误:轴中的错误(1,at=c(0,5),col=“red”,line=2.5,labels=rep(“",:plot.new未被调用Yet您需要调用plot命令,这意味着首先绘制图形,然后绘制线条如果下面是我的数据框,我如何添加线条?conc这些变量是什么意思?Ela硼酸盐。如果下面是我的数据框,我如何添加行?conc是一种方法,但是使用
segmentsGrob
&
textGrob
s,但是这些事情在基本r中做得更容易,就像在meW答案中一样
data("mtcars")
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution", 
        xlab="Number of Gears")
axis(1, # Put 1 for X-axis, 2 for Y-axis
     at=c(0, 2.5), #Limit of line
     col="red", 
     line=2.5, # how much gap you need between line and X-axis
     labels=rep("",2), # remove line labels
     lwd=2,
     lwd.ticks=0) # remove ticks

axis(1, # Put 1 for X-axis, 2 for Y-axis
     at=3+c(0, 2.5), #Limit of line
     col="blue", 
     line=2.5, # how much gap you need between line and X-axis
     labels=rep("",2), # remove line labels
     lwd=2,
     lwd.ticks=0) # remove ticks