0

I am trying to plot some data from my swim team from the last competitions.

Animated Plot here: https://i.stack.imgur.com/y3FNz.jpg

(1) To improve the visual appearance, I inserted a background image. However this background image somehow overlays the original animation. You can see it in the animation below. This background image already has 70% opacity but i still can't see the animated line properly.

(2) I also tried to animate the coloring of the line in a way that i changes its color during the animation. Meaning something like the line is red while being below the value of 6.5 and turns green when above 6.5 Is that possible at all?

For (1) I tried changing the opacity of the background image but with no success

For (2) I tried to add this to

geom_line() +
scale_colour_gradient(low="coral", high="steelblue") +

but nothing happened (no error message, too)

Full code:

library(ggplot2)
library(gganimate)
library(png)

data <- tibble::tribble(~Heat, ~Performance,
                        8.1, 5.6,
                        8.2, 5.9,
                        8.3, 5.5,
                        8.4, 6.2,
                        8.5, 6.8,
                        8.6, 7.2,
                        8.7, 7.6,
)

url <- "https://i.imgur.com/mREnnlF.png"
download.file(url, destfile = "background_image.png")
background_image <-readPNG("background_image.png")

p <- ggplot(data, aes(Heat, Performance)) + 
  geom_line(color='coral', size = 1) + 
  geom_point(color= "steelblue", size = 3) + 
  background_image(background_image) +
  transition_reveal(Heat) +
  ease_aes('cubic-in-out')

animate(p, fps = 10, end_pause=10, width = 800, height = 400)

(a) I am looking to make the animated appear clearly in the front

(b) The change of the line coloring can be either abrupt from the starting color to the next one or a smooth, animated transition. both is fine.

(c) Additionally - if possible - I want to get rid of the y axis description and instead have the values of the datapoints showed in the animation wenn the line reaches each datapoint. so that at the end of the animation, the line is shown together with the respective values at their respective datapoints.

Any help much appreciated & thx in advance to whoever can tackle this! Best Tom

TomTe
  • 193
  • 9
  • Please provide a [reproducible minimal example](https://stackoverflow.com/q/5963269/8107362). Especially, provide some sample data, e.g. with `dput()`. – mnist Nov 06 '19 at 13:12
  • What do you mean? the code above is all I have. Besides, The IMGUR Link shows the animation. Please advise. – TomTe Nov 06 '19 at 13:39
  • @wusel other than the background image being missing, they do seem to have a fully reproducible example with data – camille Nov 06 '19 at 17:07
  • yes, my bad. I just run the code and it did not work due to missingness. However, I should have been more careful about my comment. Nevertheless, the background image as such is missing which makes this example not completely reproducible, or not? – mnist Nov 06 '19 at 17:10
  • @wusel yeah, the background image part does block it from reproducible. OP, where does the `background_image` function come from? – camille Nov 06 '19 at 17:55
  • Also, you haven't assigned anything to the color, so adding a color scale won't actually do anything. This might also be better as a few questions with separate concerns, maybe one for a & b and another for c – camille Nov 06 '19 at 18:14
  • Sorry for the inconvenience. I fixed it now to fully reproducible. added the PNG library and the request of the background_image. @camille I don't know how to do this. I figured the line would change from 'coral' to 'steelblue' during the animation when given these two colors. – TomTe Nov 06 '19 at 18:43

0 Answers0