mages / googleVis

Interface between R and the Google Chart Tools
https://mages.github.io/googleVis/
360 stars 155 forks source link

gvisAnnotationChart strips characters from legend #14

Open saradickinson opened 9 years ago

saradickinson commented 9 years ago

I have a dataframe called 'df' that looks like this when dumped using write.table(): "x" "key" "y" "1" 2014-06-02 02:14:00 "aby01" 217.95 "2" 2014-06-02 00:43:00 "aby01" 222.783333333333 "3" 2014-06-02 00:48:00 "aby01" 226.716666666667 "4" 2014-06-02 02:13:00 "aby01" 216.266666666667 "5" 2014-06-02 02:04:00 "aby01" 235.9 "6" 2014-06-02 01:22:00 "aby01" 227.1

When I try to plot it with the following code:

plot <- gvisAnnotationChart(df, numvar="y", idvar = "key", datevar = "x", titlevar = "key", options=list(legendPosition='newRow', height=440, width=900))

it plots correctly, however the legend appears incorrectly as "ab1" instead of "aby01" i.e. the letter y and the following character are stripped from the legend (although the annotation title appears correctly). Please see the attached screenshot.

plot

After some investigation I worked out that if I change the third column name from "y" to "z" then the problem with the name aby01 disappears, but names including a z are then affected in a similar way!

I also wrote some html to plot the same data directly using google charts and I didn't see the problem there so I am concluding that this is an issue with the R package when transforming the data frame. I didn't see any restriction in the documentation regarding what column names can be used...

I think this issue also affects gvisAnnotatedTimeLine()

mages commented 9 years ago

I can't reproduce the problem. The following code works for me.

library(googleVis)
data(Stock)
Stock$Device <- factor(Stock$Device)
levels(Stock$Device) <- c("P01", "P02")
names(Stock)[1:3] <- c("x", "key", "y")
plt <- gvisAnnotationChart(Stock, numvar="y", idvar = "key", 
                           datevar = "x", titlevar = "key",
                           options=list(legendPosition='newRow', 
                                        height=440, width=900))

plot(plt)

annotationchart

My session info is:

R version 3.1.3 (2015-03-09)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] googleVis_0.5.8

loaded via a namespace (and not attached):
[1] RJSONIO_1.3-0 tools_3.1.3 
saradickinson commented 9 years ago

Hi,

Thanks for looking at this. The problem I saw is that if the keys contained the letter “y” is was stripped in the legend i.e. what do you see if you use this line instead:

levels(Stock$Device) <- c("Py01", "Py02”) I’ll send my session info shortly. Sara.

On 20 Apr 2015, at 07:34, Markus Gesmann notifications@github.com wrote:

I can't reproduce the problem. The following code works for me.

library(googleVis) data(Stock) Stock$Device <- factor(Stock$Device) levels(Stock$Device) <- c("P01", "P02") names(Stock)[1:3] <- c("x", "key", "y") plt <- gvisAnnotationChart(Stock, numvar="y", idvar = "key", datevar = "x", titlevar = "key", options=list(legendPosition='newRow', height=440, width=900))

plot(plt) https://cloud.githubusercontent.com/assets/1146581/7224858/8e217b50-e72f-11e4-9818-38f7270cda3e.png My session info is:

R version 3.1.3 (2015-03-09) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.3 (Yosemite)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] googleVis_0.5.8

loaded via a namespace (and not attached): [1] RJSONIO_1.3-0 tools_3.1.3 — Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94370447.

mages commented 9 years ago

Oh, I see now. Looks like a bug.

On 20 Apr 2015, at 07:46, saradickinson notifications@github.com wrote:

Hi,

Thanks for looking at this. The problem I saw is that if the keys contained the letter “y” is was stripped in the legend i.e. what do you see if you use this line instead:

levels(Stock$Device) <- c("Py01", "Py02”) I’ll send my session info shortly. Sara.

On 20 Apr 2015, at 07:34, Markus Gesmann notifications@github.com wrote:

I can't reproduce the problem. The following code works for me.

library(googleVis) data(Stock) Stock$Device <- factor(Stock$Device) levels(Stock$Device) <- c("P01", "P02") names(Stock)[1:3] <- c("x", "key", "y") plt <- gvisAnnotationChart(Stock, numvar="y", idvar = "key", datevar = "x", titlevar = "key", options=list(legendPosition='newRow', height=440, width=900))

plot(plt) https://cloud.githubusercontent.com/assets/1146581/7224858/8e217b50-e72f-11e4-9818-38f7270cda3e.png My session info is:

R version 3.1.3 (2015-03-09) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.3 (Yosemite)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] googleVis_0.5.8

loaded via a namespace (and not attached): [1] RJSONIO_1.3-0 tools_3.1.3 — Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94370447.

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94372210.

saradickinson commented 9 years ago

On 20 Apr 2015, at 07:48, Markus Gesmann notifications@github.com wrote:

Oh, I see now. Looks like a bug.

And if you change the column name from “y” to “z” then the problem disappears. And if you change the Device names to “Pz01”, “Pz02” it comes back... so must be linked to the column name somehow. Weird one….!

On 20 Apr 2015, at 07:46, saradickinson notifications@github.com wrote:

Hi,

Thanks for looking at this. The problem I saw is that if the keys contained the letter “y” is was stripped in the legend i.e. what do you see if you use this line instead:

levels(Stock$Device) <- c("Py01", "Py02”) I’ll send my session info shortly. Sara.

On 20 Apr 2015, at 07:34, Markus Gesmann notifications@github.com wrote:

I can't reproduce the problem. The following code works for me.

library(googleVis) data(Stock) Stock$Device <- factor(Stock$Device) levels(Stock$Device) <- c("P01", "P02") names(Stock)[1:3] <- c("x", "key", "y") plt <- gvisAnnotationChart(Stock, numvar="y", idvar = "key", datevar = "x", titlevar = "key", options=list(legendPosition='newRow', height=440, width=900))

plot(plt) https://cloud.githubusercontent.com/assets/1146581/7224858/8e217b50-e72f-11e4-9818-38f7270cda3e.png My session info is:

R version 3.1.3 (2015-03-09) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.3 (Yosemite)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] googleVis_0.5.8

loaded via a namespace (and not attached): [1] RJSONIO_1.3-0 tools_3.1.3 — Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94370447.

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94372210.

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94372435.

mages commented 9 years ago

Ok, I believe the following line is causing the trouble: https://github.com/mages/googleVis/blob/master/R/gvisAnnotatedTimeLine.R#L303 https://github.com/mages/googleVis/blob/master/R/gvisAnnotatedTimeLine.R#L303

On 20 Apr 2015, at 07:53, saradickinson notifications@github.com wrote:

On 20 Apr 2015, at 07:48, Markus Gesmann notifications@github.com wrote:

Oh, I see now. Looks like a bug.

And if you change the column name from “y” to “z” then the problem disappears. And if you change the Device names to “Pz01”, “Pz02” it comes back... so must be linked to the column name somehow. Weird one….!

On 20 Apr 2015, at 07:46, saradickinson notifications@github.com wrote:

Hi,

Thanks for looking at this. The problem I saw is that if the keys contained the letter “y” is was stripped in the legend i.e. what do you see if you use this line instead:

levels(Stock$Device) <- c("Py01", "Py02”) I’ll send my session info shortly. Sara.

On 20 Apr 2015, at 07:34, Markus Gesmann notifications@github.com wrote:

I can't reproduce the problem. The following code works for me.

library(googleVis) data(Stock) Stock$Device <- factor(Stock$Device) levels(Stock$Device) <- c("P01", "P02") names(Stock)[1:3] <- c("x", "key", "y") plt <- gvisAnnotationChart(Stock, numvar="y", idvar = "key", datevar = "x", titlevar = "key", options=list(legendPosition='newRow', height=440, width=900))

plot(plt) https://cloud.githubusercontent.com/assets/1146581/7224858/8e217b50-e72f-11e4-9818-38f7270cda3e.png My session info is:

R version 3.1.3 (2015-03-09) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.3 (Yosemite)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] googleVis_0.5.8

loaded via a namespace (and not attached): [1] RJSONIO_1.3-0 tools_3.1.3 — Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94370447.

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94372210.

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94372435.

— Reply to this email directly or view it on GitHub https://github.com/mages/googleVis/issues/14#issuecomment-94373448.

saradickinson commented 9 years ago

On 20 Apr 2015, at 08:12, Markus Gesmann notifications@github.com wrote:

Ok, I believe the following line is causing the trouble: https://github.com/mages/googleVis/blob/master/R/gvisAnnotatedTimeLine.R#L303 https://github.com/mages/googleVis/blob/master/R/gvisAnnotatedTimeLine.R#L303

Yeah, that looks like it would do it…

I guess the varname + “.” is being interpreted as a regular expression during the gsub and replacing the character following the varname, which explains the kind of behaviour we were seeing when trying to narrow down which names were effected!

AzamYahya commented 6 years ago

The legend element "P02-This also is suppose to be very very long name" is not completely displayed as it goes behind the annotation area. How do I change legend position for all the legend elements to become completely visible?

Here is the reproducible example

library(googleVis) data(Stock) Stock$Device <- factor(Stock$Device) levels(Stock$Device) <- c("P01-This is suppose to be a very long name", "P02-This also is suppose to be very very long name") names(Stock)[1:3] <- c("x", "key", "y") plt <- gvisAnnotationChart(Stock, numvar="y", idvar = "key", datevar = "x", titlevar = "key", options=list(legendPosition='newRow', height=440, width=900))

plot(plt)

mages commented 6 years ago

Unfortunately, I don't think this is possible with the current version of the Google Chart AP.