答案 0 :(得分:1)
示例(不包含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
多行,只需将另一个axis
命令附加为-
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
答案 1 :(得分:0)
也许facet_wrap
中的ggplot2
是一个起点:
library(magrittr)
library(ggplot2)
mtcars %>%
dplyr::mutate(hp_200 = ifelse(hp > 200, "hp > 200", "hp <= 200")) %>%
ggplot(aes(x = hp)) +
geom_histogram(binwidth = 20) +
facet_wrap(~ hp_200, scales = "free_x", strip.position = "bottom") +
ggthemes::theme_hc()
由reprex package(v0.2.1)于2019-01-02创建