2017-07-24 28 views
5

मुझे निम्नलिखित ggplotggplotly() में लिपटे में केवल एक सौंदर्य दिखाते हुए किंवदंती बनाने में परेशानी हो रही है। यह वर्तमान में प्रत्येक चरम प्रविष्टि के लिए तीन चर (shape, color, linetype) दिखाता है, लेकिन मैं केवल एक दिखाना चाहता हूं।पौराणिक कथाओं में ggplot2 को लपेटते समय पौराणिक कथाओं में अतिरिक्त चर,

इस प्लॉट में aes() मूल्यों में से केवल एक मूल्य (linetype) लेकिन अन्य मान विशिष्ट चर से मेल खाते हैं, और मेरी वेबसाइट पर कई भूखंडों में वर्दी रखा जाना चाहिए। साजिश से अन्य aes() मूल्यों को हटाकर मेरे मामले में व्यवहार्य समाधान नहीं है, क्योंकि मैं चाहता हूं कि वे इसी तरह के अन्य भूखंडों में बदल जाए। साथ ही, सूचनाओं को दिखाने के लिए पौराणिक कथाओं को छिपाने और tooltip को संशोधित करने के लिए, लेकिन वांछित अंत परिणाम नहीं है।

जब चल रहा है, निम्नलिखित कोड:

library(ggplot2) 
library(plotly) 

#aes lists 
solute_colors <- c("NO3" = "#BF1616") 
source_shapes <- c("rain"= 21) 
location_linetypes <- c("1"= 2,"2"= 1,"3"= 3) 

#create dataframe 
data <- data.frame(
    date = c(1966, 1970, 1972, 1979, 1989, 1990, 1998, 2000), 
    concentration = sample(1:8), 
    solute = c("NO3", "NO3", "NO3", "NO3", "NO3", "NO3", "NO3", "NO3"), 
    location = c("3", "1", "2", "3", "2", "1", "1", "2"), 
    source = c("rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain") 
) 

#ggplot 
ggplot(data, aes(x= date, y= concentration, linetype= location, color= solute, shape= source))+ 
    geom_point() + 
    geom_line() + 
    scale_shape_manual(values = source_shapes) + 
    scale_color_manual(values = solute_colors)+ 
    guides(shape = F, color = F)+ #removes shape and source legends in ggplot, but not in ggplotly 
    scale_linetype_manual(values = location_linetypes) 

कथा केवल linetype, जो वांछित परिणाम (here देखा) है पता चलता है। हालांकि, जब ggplotly

#ggplot p 
p<-ggplot(data, aes(x= date, y= concentration, linetype= location, color= solute, shape= source))+ 
    geom_point() + 
    geom_line() + 
    scale_shape_manual(values = source_shapes) + 
    scale_color_manual(values = solute_colors)+ 
    guides(shape = F, color = F)+ #removes shape and source legends in ggplot, but not in ggplotly 
    scale_linetype_manual(values = location_linetypes) 
#wrap p in ggplotly 
ggplotly(p) 

में यह लपेटकर कथा के रूप में

here देखा कथा पर एक ही पंक्ति के भीतर तीन aes() मूल्यों के साथ दिखाता है।

ggplotly में लपेटते समय या इस के लिए किंवदंती में मैन्युअल रूप से कोड करते समय मैं इस परिवर्तन को कैसे ओवरराइड कर सकता हूं? मैंने ggplot के भीतर विषयों को जोड़ा है जो ggplot और ggplotly दोनों में किंवदंती को ठीक करता है (जैसे legend.position और legend.title) हालांकि मुझे दिखाए गए वास्तविक चर को नियंत्रित करने के लिए कुछ भी नहीं मिला है।

मैं विंडोज संस्करण पर आर संस्करण 3.4.0 (RStudio संस्करण 1.0.143) का उपयोग कर रहा हूं। किसी भी मदद की सराहना की जाएगी!

उत्तर

2

अपने पौराणिक लेबलों का सम्मान करने के लिए ggplotly को कैसे बल देना है, लेकिन आप मैन्युअल रूप से सबकुछ ओवरराइट कर सकते हैं।

gp <- ggplotly(p) 
gp[['x']][['data']][[1]][['name']] <- '1' 
gp[['x']][['data']][[2]][['name']] <- '2' 
gp[['x']][['data']][[3]][['name']] <- '3' 
gp 

enter image description here

संबंधित मुद्दे