r - Dygraph with R - 如何使用axisLabelFormatter 作为标签的字符大小?

标签 r axis-labels dygraphs

我是 R 中 Dygraph 的新手,我用它来绘制我的数据(使用 xts)。一切正常,运行良好。

但问题是:我无法使用 axisLabelFormatter用于使标签更粗更大。这怎么可能?

此外,我可以在图表周围添加一个框架(如 x 和 y 轴的黑线)?

这里的图片解释了我的两个问题:click here for example image

下面是我正在尝试的代码:

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()

最佳答案

尝试这个:

    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()

关于r - Dygraph with R - 如何使用axisLabelFormatter 作为标签的字符大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38429892/

相关文章:

R 神经网络包对于数百万条记录来说太慢

r - R中Webshot Package使用什么浏览器

r - 错误: could not find function "overlay" after reinstall

python - 如何以 pi 的倍数设置轴刻度(Python)(matplotlib)

javascript - 如何将我的对象与数据转换为dygraphs的输入?

dygraphs - 如何根据分配给它的 Div ID 获取对 dygraph 的引用?

javascript - Dygraph 无法正常工作

r - 将前后单词连接到与 R 中的条件匹配的单词

r - 自定义缩放轴后ggplot2缺少标签

python - matplotlib 图表轴上每个标签的不同颜色?