2016-07-18 13 views
3

Ich bin neu in Dygraph in R, dass ich meine Daten (mit xts) plotten. Alles ist in Ordnung, es funktioniert gut.Dygraph mit R - Wie verwende ich axisLabelFormatter für die Zeichengröße des Labels?

Aber das Problem ist: Ich bin nicht in der Lage, axisLabelFormatter zu verwenden, um Etiketten fett und größer zu machen. Wie ist das möglich?

Kann ich außerdem einen Rahmen um das Diagramm hinzufügen (wie die schwarze Linie der x- und y-Achse)?

Das Bild hier erklären, meine 2 Fragen: click here for example image

Im Folgenden wird der Code Ich versuche:

library(shiny) 
library(dygraphs) 
library(xts) 

#------Importation des données contenues dans un .csv------ 
setwd("C:/Users/A20570/Desktop") #attention,on ne peut pas faire créer à R un dossier, il faut le créer via windows 

#----Importation données de qualité d'eau 
TabSMP=read.csv2(file="Analyse R/MC1_MC2_SMP.csv",sep=";",dec=".",na.strings = "#N/A") 
TabSMPMC1=read.csv2(file="Analyse R/MC1_SMP.csv",sep=";",dec=".",na.strings = "#N/A") 
TabSMPMC2=read.csv2(file="Analyse R/MC2_SMP.csv",sep=";",dec=".",na.strings = "#N/A") 
TabMC1Manu=read.csv2(file="Analyse R/MC1_Manu.csv",sep=";",dec=".",na.strings = "#N/A") 
TabMC2Manu=read.csv2(file="Analyse R/MC2_Manu.csv",sep=";",dec=".",na.strings = "#N/A") 
TabMC3Manu=read.csv2(file="Analyse R/MC3_Manu.csv",sep=";",dec=".",na.strings = "#N/A") 
TabMC4Manu=read.csv2(file="Analyse R/MC4_Manu.csv",sep=";",dec=".",na.strings = "#N/A") 


#-----Attribution du format de date et heure à la colonne date/heure pour chaque tableau------ 
TabSMP$DateHeure=as.POSIXct(TabSMP$DateHeure,format="%d/%m/%Y %H:%M") 
TabSMPMC1$DateHeure=as.POSIXct(TabSMP$DateHeure,format="%d/%m/%Y %H:%M") 
TabSMPMC2$DateHeure=as.POSIXct(TabSMP$DateHeure,format="%d/%m/%Y %H:%M") 
TabMC1Manu$DateHeure=as.POSIXct(TabMC1Manu$Date,format="%d/%m/%Y %H:%M") 
TabMC2Manu$DateHeure=as.POSIXct(TabMC2Manu$Date,format="%d/%m/%Y %H:%M") 
TabMC3Manu$DateHeure=as.POSIXct(TabMC3Manu$Date,format="%d/%m/%Y %H:%M") 
TabMC4Manu$DateHeure=as.POSIXct(TabMC4Manu$Date,format="%d/%m/%Y %H:%M") 
#TabB5Manu$DateHeure=as.POSIXct(TabB5Manu$Date,format="%d/%m/%Y %H:%M") 
ls.str()# vérification des reconnaissances par R des caractères numériques, textes, dates... 


TabSMPMC1_xts_Temp <- xts(TabSMP$MC1_Temp,order.by=TabSMP$DateHeure,frequency=365) 
TabSMPMC2_xts_Temp <- xts(TabSMP$MC2_Temp,order.by=TabSMP$DateHeure,frequency=365) 
TabMC3Manu_xts_Temp <- xts(TabMC3Manu$MC3_Temp,order.by=TabMC3Manu$DateHeure,frequency=365) 
TabMC4Manu_xts_Temp <- xts(TabMC4Manu$MC4_Temp,order.by=TabMC4Manu$DateHeure,frequency = 365) 

Temperature <- cbind(TabSMPMC1_xts_Temp,TabSMPMC2_xts_Temp,TabMC3Manu_xts_Temp,TabMC4Manu_xts_Temp) 

dygraph(Temperature,main="Evolution de la tempértaure") %>% 
     dyAxis("y", label = "°C ", valueRange = c(-1, 11)) %>% 
     dySeries("..1",label="MC1_Temp",strokeWidth=1.75) %>% 
     dySeries("..2",label="MC2_Temp",strokeWidth=1.75) %>% 
     dySeries("..3",label="MC3_Temp",pointSize=2.5) %>% 
     dySeries("..4",label="MC4_Temp",pointSize=2.5) %>% 
     dyOptions(colors = c("blue","orange","pink","green")) %>% 
     dyLegend(width=400) %>% 
     dyEvent(DebutVidange, "Ouverture Vanne de Fond", labelLoc = "top") %>% 
     dyEvent(FinVidange, "Fin Vidange", labelLoc = "top") %>% 
     dyShading(from =DebutVidange, to =FinVidange, color = "#F0F9FF") %>% 
     dyShading(from =DebutAssec, to =FinAssec, color = "#FFFFFF") %>% 
     dyRangeSelector() 

Antwort

0

versuchen Sie dies:

dyAxis(
     "y", 
     axisLabelFormatter = 'function(d){return d.toString().fontsize(4);}', #  makes them bigger 
     axisLabelWidth = 70 
    ) %>% 
and change the fontsize(4) to other numbers. An for bold tage the line: axisLabelFormatter = 'function(d){return d.toString().fontsize(4).bold();}', 
as: 

    dygraph(Temperature,main="Evolution de la tempértaure") %>% 
     dyAxis("y", label = "°C ", valueRange = c(-1, 11)) %>% 
     dySeries("..1",label="MC1_Temp",strokeWidth=1.75) %>% 
     dySeries("..2",label="MC2_Temp",strokeWidth=1.75) %>% 
     dySeries("..3",label="MC3_Temp",pointSize=2.5) %>% 
     dySeries("..4",label="MC4_Temp",pointSize=2.5) %>% 
     dyOptions(colors = c("blue","orange","pink","green")) %>% 
     dyLegend(width=400) %>% 
     dyEvent(DebutVidange, "Ouverture Vanne de Fond", labelLoc = "top") %>% 
     dyEvent(FinVidange, "Fin Vidange", labelLoc = "top") %>% 
     dyShading(from =DebutVidange, to =FinVidange, color = "#F0F9FF") %>% 
     dyShading(from =DebutAssec, to =FinAssec, color = "#FFFFFF") %>% 
    dyAxis(
     "y", 
     axisLabelFormatter = 'function(d){return d.toString().fontsize(4);}', # makes them bigger 
     axisLabelWidth = 70 
    ) %>% 
     dyRangeSelector() 
-1

ich auch die x-Achse erhalten, aber es ändert sich zu Zahlen: 2017.3 etc, beachten Sie, dass Sie 1 Monate hinzufügen müssen, da die Monate Januar-Dezember 0-11 in Javascript sind, hier:

dyAxis(
    "x", 
    # label = "Number", 
    axisLabelFormatter = 'function(d){ var month = (d.getMonth() +1).toString().fontsize(3) ;var year = d.getFullYear().toString().fontsize(3); return year + "."+ month}', ## + 1 since months jan-dec are 0-11 in Javascript 
    axisLabelFontSize = 20, 
    axisLabelWidth = 70 ## gets them apart, but not bigger 
) %>%