4

I am trying to make a chart in R via googleVis. How do you make the chart automatically fit the size of the screen, or rather, the browser?

library('googleVis')
Column <- gvisColumnChart(df,
                          options=list(legend='none'))
plot(Column)
cat(createGoogleGadget(Column), file="columnchart.xml")
micstr
  • 5,080
  • 8
  • 48
  • 76
user2868104
  • 297
  • 2
  • 14

1 Answers1

2

It is not very clear from documentation, who seems to want you to use pixels, say width = 200 in pixels, but you can use the word "automatic" which scales nicely.

So snippet from one of my functions:

 # where plotdt has my data with columns px and py
 plot1 <- gvisBarChart(plotdt, 
                       xvar = px,
                       yvar = c(py),
                       options = list(width = "automatic",
                                      height = "automatic")

Note in your case, add to your option list

gvisColumnChart(df,
                options=list(legend='none',
                             width = "automatic",
                             height = "automatic"))

Hope this helps others.

Plus, useful link for more on configuration options. This is for bar charts, so choose the right chart/table type for you on left of page.

TEST IT

Since there is no data above in df for those who want to play with this:

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)
micstr
  • 5,080
  • 8
  • 48
  • 76
  • Thanks @micstr, +1 for answering it. I tried your code and it does fit the width of the browser for the initial plot. But then when I change the browser, the plot does not adjust its size automatically. – user2868104 Jun 12 '15 at 15:00
  • Frankly, the question was asked about 2 years ago, and I did not write it clearly whether I wanted it to be resizing interactively or I wanted it to fit the screen at the initial plot, so I do not recall which of the above two issues I was trying to solve. But I did try my code again and it appears that without adding "automatic", the initial plot still automatically fits to the screen. Therefore, I assume adding "automatic" did not help. (It could be that googleVis changed their default setting over the past year and half such that it fits the screen by default now). – user2868104 Jun 12 '15 at 15:08