mardi 1 juillet 2014

Add data to ggvis tooltip that's contained in the input dataset but not directly in the vis


Vote count:

0




This is my input dataset:



> names(breakingbad.episodes)
[1] "season" "episode" "epnum" "epid" "title"
[6] "url.trakt" "firstaired.utc" "id.tvdb" "rating" "votes"
[11] "loved" "hated" "overview" "firstaired.posix" "year"
[16] "zrating.season" "src"


For my ggvis, I'm using the following variables firstaired.posix and rating:



> str(breakingbad.episodes[c("firstaired.posix", "rating")])
'data.frame': 62 obs. of 2 variables:
$ firstaired.posix: POSIXct, format: "2008-01-21 02:00:00" "2008-01-28 02:00:00" "2008-02- 11 02:00:00" ...
$ rating : num 87 85 84 84 83 90 87 85 88 83 ...


I successfully created my ggvis with a tooltip containing the rating information like this:



> breakingbad.episodes %>%
ggvis(x = ~firstaired.posix,
y = ~rating,
fill = ~season) %>%
layer_points() %>%
add_axis("x", title = "Airdate") %>%
add_axis("y", title = "Rating") %>%
add_legend("fill", title = "Season") %>%
add_tooltip(function(data){paste0("Rating: ", data$rating)}, "hover")


But I actually want the tooltip to contain more data, like the epid variable, so I tried:




add_tooltip(function(data){paste0("Rating: ", data$rating, "\n", "Epid: ", as.character(data$epid))}, "hover")


…Using as.character() because epid is an ordered factor – But the part of the tooltip is empty. (I also noticed the linebreak I intended \n to insert is missing, but that's a different problem).


It looks like the cause of this problem is that the vis object created by piping my dataset into ggvis doesn't contain the information I want to display, at least that's why I gathered by looking through the output of str() on the first example.



asked 38 secs ago






Aucun commentaire:

Enregistrer un commentaire