2016-07-29 8 views
0

Ich benutze plotly Bibliothek, um mich HTML interaktive Grafik, die ich bereits aus ggplot2 generieren, aber mit gestapelten Graphen, Plotly funktioniert nicht richtig.ggplot plotly API Chaos Breite Stack Bargraph

Hier ist mein ggplot Code:

if(file.exists(filename)) { 
    data = read.table(filename,sep=",",header=T) 
} else { 
    g <- paste0("=== [E] Error : Couldn't Found File : ",filename) 
    print (g) 
} 
    ReadChData <- data[data$Channel %in% c("R"),] 
    #head(ReadChData,10) 

# calculate midpoints of bars (simplified using comment by @DWin) 
Data <- ddply(ReadChData, .(qos_level), 
    transform, pos = cumsum(AvgBandwidth) - (0.5 *AvgBandwidth) 
) 

# library(dplyr) ## If using dplyr... 
# Data <- group_by(Data,Year) %>% 
# mutate(pos = cumsum(Frequency) - (0.5 * Frequency)) 

# plot bars and add text 
g <- ggplot(Data, aes(x = qos_level, y = AvgBandwidth)) + 
    scale_x_continuous(breaks = x_axis_break) + 
    geom_bar(aes(fill = MasterID), stat="identity", width=0.2) + 
    scale_colour_gradientn(colours = rainbow(7)) + 
    geom_text(aes(label = AvgBandwidth, y = pos), size = 3) + 
    theme_set(theme_bw()) + 
    ylab("Bandwidth (GB/s)") + 
    xlab("QoS Level") + 
    ggtitle("Qos Compting Stream") 

png(paste0(opt$out,"/",GraphName,".png"),width=6*ppi, height=6*ppi, res=ppi) 
print (g) 

library(plotly) 
p <- ggplotly(g) 
#libdir arugumet will be use to point to commin lib 
htmlwidgets::saveWidget(as.widget(p), selfcontained=FALSE, paste0(opt$out,"/qos_competing_stream.html")) 

und hier ist die HTML-Ausgabe Form plotly lib

http://pasteboard.co/2fHQfJwFu.jpg

Bitte helfen.

Antwort

3

Dies ist vielleicht ziemlich spät zu beantworten. Aber für jemanden, der das Problem in Zukunft haben könnte ...

Der geom_bar 's Breite Parameter wird nicht von ggplotly Funktion erkannt.

  1. Arbeit um: Eine Arbeit um (nicht sehr gut) von colour="white", size = 1 Parametern. Dies fügt im Grunde eine weiße Linie um die Balken hinzu und erzeugt so einen Effekt wie Leerraum. Sie könnten versuchen, die folgenden: stat_summary(aes(fill = MasterID), geom="bar", colour="white", size = 1, fun.y = "sum", position = "stack")

  2. Bessere Lösung: Verwenden bargap Parameter aus layout Funktion. Der Code sollte sein: ggplotly(type='bar', ...) %>% layout(bargap = 3, autosize=T)

P. S. Der Code in Frage Code ist nicht ausführbar, löst einen Fehler aufgrund fehlenden Dateinamens aus.

+0

danke. Ich fing an, plotly Javascript im offiline Modus zu benutzen, anstatt vom ggplot Gegenstand zu erzeugen. wird jedoch die Antwort akzeptieren. – vjain419