【问题标题】:R. doing cool plot, no X labelsR. 做很酷的情节,没有 X 标签
【发布时间】:2015-10-03 18:08:35
【问题描述】:

我无法在 x 上获取我的月份标签(比如说 Jan/15)。尝试了所有的东西,有什么诀窍? 如果我使用 YYYYMM 还可以,但我需要更具可读性。是否也可以更改背景颜色?

require(shiny)
require(rCharts)

x <- data.frame(Category=factor(c("Alpha", "Alpha","Alpha","Alpha","Alpha")), 
                    YYYYMM= factor(c("2/1/2015","3/1/2015","4/1/2015","5/1/2015","6/1/2015")),
                    COUNT=c(44,22,37,76,97))

str(x)
to_jsdate2 <- function(x){
  as.numeric(as.POSIXct(as.Date(x), origin="1970-01-01")) * 1000}

x$DATEPX <-  to_jsdate2(as.Date(x$YYYYMM))

myplot <- hPlot(COUNT ~ YYYYMM, data=x, type="line")
#myplot$xAxis(title = list (text = "Time"), type= "datetime")
myplot

而我这样做 x 标签消失了

myplot <- hPlot(COUNT ~ DATEPX, data=x, type="line")
myplot$xAxis(title =list (text = "Month") , type= "datetime")
myplot

【问题讨论】:

    标签: r rcharts


    【解决方案1】:

    要获得像 "Jan/15" 这样的标签,您需要通过 strptime 将日期传递到自纪元以来的时间,然后通过 strftime 将它们设置为相应的格式。无需将日期乘以 1000 等。 对于您的情况,请告诉我以下是否可行。您可以通过在R REPL 中执行?strptime 和?strftime 来阅读有关日期格式的更多信息。

    x$dmy = strftime(strptime(x$YYYYMM, format = "%m/%d/%Y"), format = "%b/%y")
    myplot <- hPlot(COUNT ~ dmy, data=x, type="line")
    myplot
    

    不确定如何更改rcharts中的背景颜色

    【讨论】:

    • 只找到一篇相关帖子:stackoverflow.com/questions/21081469。它所指向的只是编辑使用图表生成的样式表。也许您可以在rcharts github repo 中打开一个问题,以直接通过rcharts 绘图函数调用完成背景颜色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    相关资源
    最近更新 更多