【问题标题】:How to change color in plot and the table of labels in plot?如何更改绘图中的颜色和绘图中的标签表?
【发布时间】:2014-01-27 07:19:59
【问题描述】:
plot(donnees.test$y,esvr1.pred,xlab = "Predicted Vlues", ylab = "Actual Values",type="p", yaxs="i",ylim=c(2,18),xaxs="i",xlim=c(2,18))
points(donnees.test$y,esvr1.pred, col=1,pch =19)
points(donnees.test$y,esvr1.pred, col=2,pch =20)
points(donnees.test$y,ANFIS, col=6,pch =3)
points(donnees.test$y,NN, col=4,pch =4)
#points(donnees.test$y,esvr1.pred, col=3)
abline(a = 0, b = 1, col = 3)
abline(a = 0, b = 1.25, col = 2)
text(9,14, "+25% Line", col = 2, adj = c(-.1, -.1))
abline(a = 0, b = 0.75, col = 2)
text(14.2,10, "-25% Line", col = 2, adj = c(-.1, -.1))
leg.txt <- c("SVR_rbf", "SVR_poly","ANFIS","NN")
legend(list(x = 2,y = 17.95), legend = leg.txt, col = 1:6, pch = c(19,20,3,4))

我更改了我想要的 ANFIS 颜色,但在标签表中,ANFIS 的颜色没有改变。我应该如何改变它? 如果我想在绘图选项卡的绘图上方添加一些文本,我应该将哪些代码添加到我的源代码中?

【问题讨论】:

    标签: r colors plot


    【解决方案1】:

    要为情节添加标题,请使用参数

    main="the title here"
    

    在你的 plot 命令中,或者如果你之后添加它,使用

    title("the title here").
    

    您对图例中颜色的问题是您的图例中有四个项目:

    ("SVR_rbf", "SVR_poly","ANFIS","NN"),
    

    但是你给 plot 命令提供了六种颜色:

    col = 1:6.
    

    试试看

    col=1:4
    

    改为。

    【讨论】:

    • 所以,感谢您对标题的指导。我这样做如下: title("esvr.rmse=0.301618754780172, esvr.rss=6.09524950675449",cex.main=0.95,col.main=1,font.main=1) 关于颜色我将 1:6 更改为 1: 4 但是当我改变颜色时:points(donnees.test$y,ANFIS, col=6,pch =3) 绘图表中ANFIS的颜色没有改变。是怎么回事?
    • col=6 将使用粉红色“6”绘制所有这些点。您希望这些点是什么颜色?尝试col="black"col=2 而不是col=6。他们现在与以前不同了吗?
    • 我将颜色更改为 6:points(donnees.test$y,ANFIS, col=6,pch =3) 但图中项目的颜色已更改。标签框中该标签的颜色没有更改为 col=6。我也可以在哪里更改?
    • 啊,在传说中。传说与情节非常不同。要更改图例中使用的颜色,您必须更改图例命令legend(list(x = 2,y = 17.95), legend = leg.txt, col = 1:6, pch = c(19,20,3,4)) 中使用的颜色。将col=1:6 更改为col=c(1, 2, 6, 4);这应该使您的图例中的第三项 "ANFIS" 变为粉红色(颜色 6)。
    猜你喜欢
    • 2020-12-26
    • 2011-06-13
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    相关资源
    最近更新 更多