R legend pch mix of character and numeric

前端 未结 5 1353
忘掉有多难
忘掉有多难 2020-12-31 04:28

Is it possible to use a mix of character and number as plotting symbols in R legend?

plot(x=c(2,4,8),y=c(5,4,2),pch=16)
points(x=c(3,5),y=c(2,4),pch=\"+\")
l         


        
5条回答
  •  被撕碎了的回忆
    2020-12-31 05:10

    My first thought is to plot the legend twice, once to print the character symbols and once to print the numeric ones:

    plot(x=c(2,4,8),y=c(5,4,2),pch=16)
    points(x=c(3,5),y=c(2,4),pch="+")
    legend(7,4.5,pch=c(NA,16),legend=c("A","B")) # NA means don't plot pt. character 
    legend(7,4.5,pch=c("+",NA),legend=c("A","B"))
    

    NOTE: Oddly, this works in R's native graphical device (on Windows) and in pdf(), but not in bmp() or png() devices ...

    enter image description here

提交回复
热议问题