我想创建一个ggplot刻面网格,其中网格的x轴(而不是绘图)是标签,而不是挤压每个统计图。
示例:
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.5",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"laravel/dusk": "^4.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "3.*"
}
我希望网格的水平部分不是每个单独的图表,而是在每个单独的图表上具有3到9。
换句话说,每个条形图应仅是单列条形图。
我该怎么做?
答案 0 :(得分:2)
使用一个常量作为x值,同时仍然用cyl进行分面:
library(tidyverse)
mtcars %>%
group_by(mpg) %>%
mutate(cnt = n()) %>%
ggplot(aes(x = 1, y = cnt)) +
geom_bar(stat = "identity") +
facet_grid(vs ~ cyl) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
labs(x = "cyl")
答案 1 :(得分:1)
喜欢吗?
mtcars %>%
group_by(mpg) %>%
mutate(cnt = n()) %>%
ggplot(aes(x = cyl, y = cnt)) +
geom_bar(stat = "identity") +
facet_grid(vs ~ cyl)+
theme(axis.text.x = element_blank(),axis.ticks = element_blank())
还是这样?
mtcars %>%
group_by(mpg) %>%
mutate(cnt = n()) %>%
ggplot(aes(x = cyl, y = cnt)) +
geom_bar(stat = "identity") +
facet_grid(vs ~ cyl, scales="free")+
theme(axis.text.x = element_blank(),axis.ticks = element_blank())