我正在尝试获得一个简单的条形图,其中我的数据包含正数和负数。想要使正面和负面的颜色不同。
data <- c(-0.52, 0.25, 0.07, -0.44, 0.04, -0.16, -0.45, -1.44, -0.12, -0.17, -0.54, -0.04, -0.47, -0.40, 0.03, -0.78, -0.35 -0.52, 0.25, -0.69, 0.08, 1.11)
barplot(data, col=c("blue","black"))
我尝试使用矢量作为颜色
barplot(data,col=c("blue", "blue", "black", "blue", "black", "blue", "blue", "blue",
"blue", "blue", "blue", "blue", "blue", "blue", "black", "blue",
"blue", "blue", "black", "blue", "black", "blue"))
但它只需要第一种颜色。是否有可能在没有ggplot的基础图形中获取它?感谢您的回复