2016-07-06 3 views
1

나는 ggplot2에서 색상 및 모양에 대한 범례를 만드는 방법을 stackoverflow에서 찾았습니다. ggplotly를 사용하여 색상 및 모양 모두 범례를 만들려면 어떻게합니까?

enter image description here

이 주셔서 감사합니다

library(ggplotly) 
ggplotly(essai) 
...

state1 <- c(rep(c(rep("N", 7), rep("Y", 7)), 2)) 
year <- rep(c(2003:2009), 4) 
group1 <- c(rep("C", 14), rep("E", 14)) 
group2 <- paste(state1, group1, sep = "") 
beta <- c(0.16,0.15,0.08,0.08,0.18,0.48,0.14,0.19,0.00,0.00,0.04,0.08,0.27,0.03,0.11,0.12,0.09,0.09,0.10,0.19,0.16,0.00,0.11,0.07,0.08,0.09,0.19,0.10) 
lcl <- c(0.13,0.12,0.05,0.05,0.12,0.35,0.06,0.13,0.00,0.00,0.01,0.04,0.20,0.00,0.09,0.09,0.06,0.06,0.07,0.15,0.11,0.00,0.07,0.03,0.05,0.06,0.15,0.06) 
ucl <- c(0.20,0.20,0.13,0.14,0.27,0.61,0.28,0.27,0.00,1.00,0.16,0.16,0.36,0.82,0.14,0.15,0.13,0.13,0.15,0.23,0.21,0.00,0.15,0.14,0.12,0.12,0.23,0.16) 
data <- data.frame(state1,year,group1,group2,beta,lcl,ucl) 
pd <- position_dodge(.65) 

essai <- ggplot(data = data,aes(x= year, y = beta, colour = group2,shape = group2)) + 
geom_point(position = pd, size = 4) + 
geom_errorbar(aes(ymin = lcl, ymax = ucl), colour = "black", width = 0.5, position = pd) + 
scale_colour_manual(name = "Treatment & State", 
        labels = c("Control, Non-F", "Control, Flwr", "Exclosure, Non-F", "Exclosure, Flwr"), 
        values = c("blue", "red", "blue", "red")) + 
scale_shape_manual(name = "Treatment & State", 
       labels = c("Control, Non-F", "Control, Flwr", "Exclosure, Non-F", "Exclosure, Flwr"), 
       values = c(19, 19, 17, 17)) 
essai 

enter image description here

을하지만 할 때 그것은 ggplotly, 전설은 중복 및 라벨이 표시됩니다 :이 예는 완벽하게 작동 도움

+0

내가 잘못 될 수도, 나는 희망,하지만 난 그것을 plotly – MLavoie

+0

오 두 전설을 가질 수 생각하지 않습니다. 고맙습니다 –

답변

0

당신은 미국으로 생각 했습니까? 이 작업을 수행하려면 plot_ly() 함수를 사용 하시겠습니까? 올바르게 읽은 경우 대화 형 플롯으로 작업하려면 색상과 모양이 모두 하나만 필요합니다. 나는 누군가가 해결책을 알아낼 것이다 신뢰 ... I've linked their reference/attribute page.

plottest <- plot_ly(data = data,x= year, y = beta, 
type = "scatter", symbol = group2, 
symbols = c("circle", "square", "triangle-down","triangle-up"),mode = "markers", 
error_y = list(
     type = "data", 
     symmetric = FALSE, 
     array = c(ucl), 
     arrayminus = c(lcl)) 
) 
관련 문제