使用下面的代码,我生成一组简单的直方图:
os.system('clear')
我想保持生成没有data(mtcars); Vectorize(require)(package = c("ggplot2", "ggthemes", "dplyr"))
mtcars %>%
add_rownames(var = "model") %>%
gather(var, value, -model, -am) %>%
filter(var %in% c("hp")) %>%
# Define chart
ggplot(aes(value)) +
geom_histogram(aes(y = ..ncount..), colour = "black", fill = "gray58",
binwidth = 15) +
geom_density(aes(y = ..scaled..), colour = "red") +
facet_wrap( ~am, ncol = 3, scales = "free")
特殊变量的直方图时产生的比例,如下例所示:
..ncount..
但它使mtcars %>%
add_rownames(var = "model") %>%
gather(var, value, -model, -am) %>%
filter(var %in% c("hp")) %>%
# Define chart
ggplot(aes(value)) +
geom_histogram(colour = "black", fill = "gray58",
binwidth = 15) +
geom_density(aes(y = ..scaled..), colour = "red") +
facet_wrap( ~am, ncol = 3, scales = "free")
看起来很差。
所以我想要归结为:
geom_density
轴的比例