在 geom_bar 上使用 fill 参数不会给我的绘图上的条形着色。我正在使用泰坦尼克号数据集中的 train.csvhere https://www.kaggle.com/c/titanic/data.
passengers <- read.csv('../input/train.csv')
我尝试将填充移到 aes() 之外,尝试将 aes 移到 ggplot() 函数。
这是我在泰坦尼克号数据集上使用的代码
ggplot(data = passengers) +
geom_bar(mapping = aes(x=Survived, fill = Pclass))
这是我用作模板的代码,它在钻石数据内置的 ggplot 上运行良好。
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = cut))
我只是不断地用 geom_bar 获得灰色条,以使用 Pclass 作为填充来生存。
这对我来说很有效:
ggplot(data = passengers) +
geom_bar(mapping = aes(x=Survived, fill = as.character(Pclass)))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)