【问题标题】:R graph not displaying correctlyR 图形显示不正确
【发布时间】:2015-01-10 18:07:10
【问题描述】:

我在下面有一个图表,我想知道为什么图表上的内容没有正确显示?

time<- as.POSIXct(c("2014-12-10 20:51:53.103","2014-12-10 20:56:54.204"), tz= "GMT")
p<-c(49.32, 60)
s<-c("B","")
pointcolor<-c("red","black")
share<-c(35,0)
pointsize<-c(1.01,1)
shapeType<-c(16,10)
bigDF<-data.frame(time=time, p=p, s=s, pointcolor=pointcolor, share=share, pointsize=pointsize, shapeType=shapeType)
bigDF
ggplot(bigDF, aes(x=time, y=p)) + geom_line() + geom_point( aes(shape = as.factor(shapeType),size = pointsize, color = pointsize)) 

当您运行时,您应该看到第一个点是红色的,但它显示为绿松石。这是为什么呢?

【问题讨论】:

    标签: r


    【解决方案1】:

    这是因为 ggplot 用于离散色标的默认调色板。你可以这样改变:

    ggplot(bigDF, aes(x=time, y=p)) + 
      geom_point( aes(shape = as.factor(shapeType),size = pointsize, color = pointcolor)) 
      scale_color_manual(values = levels(bigDF$pointcolor))
    

    在哪里

    levels(bigDF$pointcolor)
    [1] "black" "red" 
    

    【讨论】:

      【解决方案2】:
      ggplot(bigDF, aes(x=time, y=p)) + 
       geom_line() + 
       geom_point(aes(shape = as.factor(shapeType)),size = pointsize, color = pointcolor) 
      

      会给你排序。您将颜色参数放在 aes 调用中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-06
        • 2017-11-24
        • 2012-12-05
        • 1970-01-01
        • 2023-01-12
        • 1970-01-01
        • 2019-12-28
        • 1970-01-01
        相关资源
        最近更新 更多