Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dygraph with R - How to use axisLabelFormatter for label's character size?

I am new to Dygraph in R, that I use to plot my data (with xts). Everything is OK, it works well.

But the problem is: I'm not able to use axisLabelFormatter for making labels bold and bigger. How is that possible?

Further, can I add a frame around the chart (like the black line of x and y axis)?

The image here explain my 2 questions: click here for example image

Below is the code I am trying:

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

#------Importation des données contenues dans un .csv------
setwd("C:/Users") #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()
like image 707
CDCD Avatar asked Nov 09 '22 12:11

CDCD


1 Answers

try this:

    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()
like image 98
4554888 Avatar answered Nov 15 '22 08:11

4554888