gpt4 book ai didi

r - 更改 googleVis 时间轴图表上的轴限制

转载 作者:行者123 更新时间:2023-12-02 09:06:24 24 4
gpt4 key购买 nike

我想为 R googleVis 时间线图表设置具体的开始和结束日期。例如,我希望下面的图表从 1780 开始,到 1815 结束。我搜索了文档并尝试了其他图表类型中的一些选项,但我无法让其中任何一个发挥作用。

library(googleVis)
datTL <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
Name=c("Washington", "Adams", "Jefferson",
"Adams", "Jefferson", "Burr"),
start=as.Date(x=rep(c("1789-03-29", "1797-02-03",
"1801-02-03"),2)),
end=as.Date(x=rep(c("1797-02-03", "1801-02-03",
"1809-02-03"),2)))

Timeline <- gvisTimeline(data=datTL,
rowlabel="Name",
barlabel="Position",
start="start",
end="end",
options=list(timeline="{groupByRowLabel:false}",
backgroundColor='#ffd',
height=350,
colors="['#cbb69d', '#603913', '#c69c6e']"))
plot(Timeline)

enter image description here

最佳答案

您可以通过 hAxis 在如下选项中提供水平轴的 minValuemaxValue:
option=list(hAxis="{minValue: 新日期(1785, 0, 0), maxValue: 新日期(1810, 0, 0)}"))

整个情节是这样的:

library(googleVis)
datTL <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
Name=c("Washington", "Adams", "Jefferson",
"Adams", "Jefferson", "Burr"),
start=as.Date(x=rep(c("1789-03-29", "1797-02-03",
"1801-02-03"),2)),
end=as.Date(x=rep(c("1797-02-03", "1801-02-03",
"1809-02-03"),2)))

option_list <- list(timeline="{groupByRowLabel:false}",
backgroundColor='#ffd',
height=350,
colors="['#cbb69d', '#603913', '#c69c6e']",
hAxis="{minValue: new Date(1785, 0, 0), maxValue: new Date(1810, 0, 0)}")

Timeline <- gvisTimeline(data=datTL,
rowlabel="Name",
barlabel="Position",
start="start",
end="end",
options=option_list)
plot(Timeline)

关于r - 更改 googleVis 时间轴图表上的轴限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49654503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com