2015-01-12 2 views
0
time<- as.POSIXct(c("2014-12-10 20:51:53.103","2014-12-10 20:56:54.204","2014-12-10 20:57:54.204"), tz= "GMT") 
p<-c(49.32, 60,50) 
s<-c("B","","S") 
pointcolor<-c("green","black","red") 
share<-c(35,0,6) 
pointsize<-c(10,5,10) 
shapeType<-c(16,10,16) 
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 = as.factor(pointsize), 
    #    color = pointcolor)) + 
    #scale_color_manual(values = c("black", "green", "red")) + 
    #scale_size_manual(values = 10) 

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

당신은 볼 수 있습니다 :변경 전설

enter image description here

내가 그렇게 shapetype 및 포인트 사이즈 전설을 제거 할 내가 할 :

그래프에이 2 추가 :

ggplot(bigDF, aes(x=time, y=p)) + geom_line() + 
    geom_point(aes(shape = as.factor(shapeType), 
        size = as.factor(pointsize), 
        colour = pointcolor)) + 
    scale_color_manual(values = levels(as.factor(bigDF$pointcolor)) )+ scale_shape_identity(guide="none") + scale_size_identity(guide="none") 

는 오류가 발생합니다 :

Error: non-numeric argument to binary operator 

이는 scale_size_identity (guide = "none") 때문입니다. 포인트 크기의 범례를 제거하는 방법을 알고 있습니까?

또한 검정색, 녹색, 빨간색 대신에 "녹색"은 "구매", 빨간색은 "판매"라고 표시되도록 색상 범례를 변경하는 방법을 알고 있습니까?

감사합니다.

답변

1
levels(bigDF$pointcolor) <- c(NA, "Buy", "Sell") 

ggplot(bigDF, aes(x=time, y=p)) + geom_line() + 
    geom_point(aes(shape = as.factor(shapeType), 
        size = as.factor(pointsize), 
        colour = pointcolor)) + 
    scale_color_manual(name = "Status", values = c("Sell" = "red", "Buy" = "green"))+ scale_shape_discrete(guide=FALSE) + scale_size_discrete(guide = FALSE) 

enter image description here

+0

감사 @RStudent! 전설에 "BUY"또는 "판매"라고 말하면서 scale_color_manual (값 = 레벨 (as.factor (bigDF $ PointColor)), 레이블 = c ("", "Buy", "Sell"))하지만 검은 점이 계속 나타납니다. 그리고 전설의 제목을 바꾸는 것도 알고 있습니까? "PointColor"에서 "Status"까지? 고맙습니다! – user3022875