rAmCharts使用填充颜色生成奇怪的xy-plot

时间:2018-04-23 21:06:37

标签: r amcharts

我使用包amChartsR中创建了一个简单的rAmCharts。对于我的数据,此图表很简单XY chart,我想在图表线下填充区域直到x轴。

Dat = data.frame(x = 0:10, y = c(9, 11, 4,7,8,9,7,6,2, 2,1))
amXYChart(x = Dat$x, y = Dat$y) %>%
    setDataProvider(dataProvider = Dat, keepNA = TRUE) %>%
    addGraph(xField = "x", yField = "y", lineColor = '#058e54', fillAlphas = 0.5, bullet = "round", lineThickness = 1, bulletColor = "transparent")

如你所见,amCharts正在生成一个看起来很奇怪的情节,它无法填充该区域直到x轴。

我尝试添加参数fillToAxis = "x",如下所示,然后图表根本没有填充该区域。

addGraph(xField = "x", yField = "y", lineColor = '#058e54', fillAlphas = 0.5, bullet = "round", lineThickness = 1, bulletColor = "transparent", fillToAxis = "x")

如果有人指导我使用正确的代码填充x轴上的区域,我将非常感激。

谢谢,

1 个答案:

答案 0 :(得分:1)

您应该在点序列中添加两个元素:原点(0,0)和坐标点(10,0)。

Dat2 <- data.frame(x=c(0,Dat$x,10),y=c(0,Dat$y,0))
amXYChart(x="x", y="y", dataProvider=Dat2, keepNA = TRUE) %>%
    addGraph(xField = "x", yField = "y", lineColor = '#058e54', fillAlphas = 0.5, 
    bullet = "round", lineThickness = 1, bulletColor = "transparent")

enter image description here