我正在尝试使用googleVis
在R中制作图表。如何使图表自适应屏幕大小,或者说浏览器的大小?
library('googleVis')
Column <- gvisColumnChart(df,
options=list(legend='none'))
plot(Column)
cat(createGoogleGadget(Column), file="columnchart.xml")
从文档中并不是很清楚,似乎要求您使用像素,例如在像素中使用width = 200
,但是您可以使用单词"automatic",它可以很好地进行缩放。
因此,以下是我其中一个函数的片段:
# where plotdt has my data with columns px and py
plot1 <- gvisBarChart(plotdt,
xvar = px,
yvar = c(py),
options = list(width = "automatic",
height = "automatic")
gvisColumnChart(df,
options=list(legend='none',
width = "automatic",
height = "automatic"))
希望这能帮助到其他人。
此外,以下是有关配置选项的有用链接。 这是针对条形图的,所以请在页面左侧选择适合您的正确图表/表格类型。
测试一下
由于上方的df
中没有数据供那些想要玩的人使用:
library('googleVis')
# some test data, add your own
df <- data.frame(x = c(1,2,3),
y = c(2,4,6))
plotdata <- gvisColumnChart(df,
options=list(legend='none',
width = "automatic",
height = "automatic"))
plot(plotdata)