我已经尝试寻找这个看似简单的问题的解决方案,但无济于事。我要做的就是在ggplot中绘制一条线,并在线周围绘制标准偏差。但是,我一直在恢复这个错误:
Error: Discrete value supplied to continuous scale
我的数据框plotdata
如下:
sites Spoly Spolylower Spolyupper
526.790 0.03018671 0.1196077 0.1196077
1538.512 0.04106053 0.1429613 0.1429613
2540.500 0.02896953 0.1127456 0.1127456
3541.000 0.03560484 0.1200609 0.1200609
4560.143 0.06038193 0.1564464 0.1564464
5569.831 0.03608714 0.1296704 0.1296704
我可以完美地描绘这条线:
ggplot(data = plotdata, aes(x = "Sites", y = "Mean Values")) +
geom_line(aes(x = sites, y = Spoly), color = "steelblue")
但是当我尝试添加功能区时,我收到错误:
ggplot(data = plotdata, aes(x = "Sites", y = "Mean Values")) +
geom_line(aes(x = sites, y = Spoly), color = "steelblue") +
geom_ribbon(aes(x = sites, ymin = Spolylower, ymax = Spolyupper), alpha = 0.3)
Error: Discrete value supplied to continuous scale
发生了什么事?我在这里做错了什么?
答案 0 :(得分:0)
我认为你应该试试这个:
ggplot(data = plotdata, aes(x = "Sites", y = "Mean Values")) +
geom_line(aes(x = sites, y = Spoly), color = "steelblue") +
geom_ribbon(aes(ymin = plotdata$Spolylower, ymax = plotdata$Spolyupper),fill="dimgray", alpha = 0.1)
告诉我它是否有效