Как добавить строку под метками оси в ggplot2? - PullRequest
0 голосов
/ 02 января 2019

Как добавить линию под метками осей, как на прикрепленном рисунке, где есть линии под метками осей 50 100 и 200? enter image description here

Ответы [ 2 ]

0 голосов
/ 02 января 2019

Может быть, 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()

Создано в 2019-01-02 пакетом Представление (v0.2.1)

0 голосов
/ 02 января 2019

Пример (не содержит 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

plt

Несколько строк, просто добавьте еще одну команду 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

plt2

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...