Is this possible. I want to do something like
library(plotly)
library(dplyr)
df <- data.frame(a=c(1,2,3,4,5,6),b=c(3,5,2,6,8,1),c=c("p","p","q","r","r","r"),
d=c("v","v","w","v","v","v"), stringsAsFactors= F)
df %>%
plot_ly(x=a,y=b,mode="markers",type="scatter", color=c,
marker = list(
symbol=d)
)
But the different symbol I want on third data point is not appearing
Also is it possible to set the symbols to be other than default
TIA
Just copying my comment here:
If you want to stick with plotly
, you can use:
df %>% plot_ly(x=a,y=b,mode="markers", symbol=d, color=c)
You can also define your symbols with:
symbols = c("cross", "square", "triangle-down")
EDIT: You could create an interaction and then use this new factor as a symbol. You will have only one legend (I don't think having two legends is possible with native plotly
).
df$Int <- interaction(df$c, df$d)
df %>% plot_ly(x=a,y=b,mode="markers", symbol=Int)
But you could also use ggplot2
using:
ggplot(data=df, aes(x=a, y=b, shape=d, color=c)) + geom_point()
ggplotly()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.