一个快速收拾rownames的是,你可以做以下的列。
我们使用factor()
的美学色彩,使之成为独立/ 当刻面,以达致这看你需要为scale
和space
指定"free_y"
。
基地
library(tidyverse)
mtcars2 = rownames_to_column(mtcars, "car")
ggplot(mtcars2, aes(x = mpg, y = factor(car), color = factor(cyl))) +
geom_point(shape = 1) +
facet_grid(cyl ~ ., scales = "free_y", space = "free_y") +
theme_bw() +
theme(panel.grid = element_blank(),
panel.grid.major.y = element_line(size=.1, color="grey90"),
legend.position = "none") +
ggtitle("Gas Milage for Car Models\ngrouped by cylinder") +
xlab("Miles Per Gallon") +
ylab("")
添加文本
ggplot(mtcars2, aes(x = mpg, y = factor(car), color = factor(cyl))) +
geom_point(shape = 1) +
geom_text(aes(label = mpg), colour = "grey40", size = 3, hjust = -0.3) +
facet_grid(cyl ~ ., scales = "free_y", space = "free_y") +
theme_bw() +
theme(panel.grid = element_blank(),
panel.grid.major.y = element_line(size=.1, color="grey90"),
legend.position = "none") +
ggtitle("Gas Milage for Car Models\ngrouped by cylinder") +
xlab("Miles Per Gallon") +
ylab("")
你或许可以使用geom_label
而不是geom_text
在这里效果很好。
一个侧面说明,你可能只是做'C( “红”, “蓝”,” darkgreen“)[x $ cyl]''color ='参数到'dotchart' – thelatemail
@thelatemail,好点,赞同,我实际上玩的是不同的参数,比如线条大小,颜色等等。 –