我对R(第2天)非常新。我正在整理一个条形图,但我不断地将二进制运算符的"非数字参数。下面是我到目前为止所写的所有代码。有什么建议?我理解这是(+)错误但不确定如何纠正它并仍然接收我的图表。
我试图删除guides(fill=FALSE)
,但后来我没有得到图表:
plot <- ggplot(data=sumcult5ml, aes(x=reorder(cultivar,eggs5ml, y=eggs5ml)))
geom_bar(aes(fill="sumcult5ml", TRUE),stat="bin", width=.5)
mapping: x = TRUE, fill = sumcult5ml
geom_bar: width = 0.5, na.rm = FALSE
stat_bin: width = 0.5, na.rm = FALSE
position_stack
代码:
plot <- ggplot(data=sumcult5ml, aes(x=reorder(cultivar,eggs5ml, y=eggs5ml)))
geom_bar(aes(fill="sumcult5ml", TRUE),stat="bin", width=.5) + guides(fill=FALSE)
错误:
> plot <- ggplot(data=sumcult5ml, aes(x=reorder(cultivar,eggs5ml, y=eggs5ml)))
> geom_bar(aes(fill="sumcult5ml", TRUE),stat="bin", width=.5) + guides(fill=FALSE)
Error in geom_bar(aes(fill = "sumcult5ml", TRUE), stat = "bin", width = 0.5) + :
non-numeric argument to binary operator
感谢您的任何提示!
答案 0 :(得分:1)
使用+
运算符添加绘图元素,如下所示:
plot <- ggplot(data=sumcult5ml, aes(x=reorder(cultivar,eggs5ml, y=eggs5ml))) +
geom_bar(aes(fill="sumcult5ml", TRUE),stat="bin", width=.5) + guides(fill=FALSE)
请注意第1行末尾的+
。