Reputation: 9018
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)) )
when you plot it you will see:
I want to remove the shapetype and pointsize legends so I do:
add these 2 to the graph:
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")
I get an error:
Error: non-numeric argument to binary operator
this is due to scale_size_identity(guide="none"). Do you know how to remove the pointsize legend?
Also - Do you know how to change the color legend so that instead of reading black, green, red it will say only "Buy" for green and "Sell" for red?
Thank you.
Upvotes: 0
Views: 317
Reputation: 9618
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)
Upvotes: 1