R: Как я могу заставить точки рассеяния (geom_point) исчезать, уменьшая размер в анимации? - PullRequest
0 голосов
/ 27 января 2020

Я новичок в R, но меня привлекли приятные инструменты визуализации.

Я ищу хороший способ затухания точек рассеяния, уменьшаясь в размерах с течением времени. Это мой код:

# Reading libraries
library(gganimate)
library(ggplot2)
library("readxl")

# Reading dataframe
df1 <- read_excel("prices.xlsx")

# Create a group-means data set
ag <- aggregate(df1$SpotPriceEUR, list(df1$PriceArea), mean)

# Specifying plot/animation features
p <- ggplot() +
  geom_point(data = df1, aes(x=SpotPriceEUR, y = PriceArea, colour = SpotPriceEUR,size=2),show.legend=FALSE) +
  geom_point(data = ag, aes(x=ag$x, y = ag$Group.1, size = 1, shape=8),color = "blue",show.legend=FALSE) +
  scale_shape_identity() +
  scale_colour_continuous(low = "green", high = "red",guide = "colourbar") +  
  transition_time(Hour) +
  scale_alpha(range = c(0,1)) +
  guides(alpha = F) +
  theme_minimal() +
  labs(title = "Date: {frame_time}",x = "Spot Price [EUR]",y = "Price Area")

# Animate
animate(p)

Вот что я получил:

enter image description here

Надеюсь, вы можете визуализировать то, что я ищу .

Всего наилучшего, DW

Бонус: Я также ищу способ случайного смещения точек рассеяния на оси Y.

1 Ответ

0 голосов
/ 01 февраля 2020

Взгляните на [enter/exit() functions][1] в gganimate

Я думаю, вы хотите что-то вроде:

    p <- ggplot() +
      geom_point(data = df1, aes(x=SpotPriceEUR, y = PriceArea, colour = SpotPriceEUR,size=2),show.legend=FALSE) +
      geom_point(data = ag, aes(x=ag$x, y = ag$Group.1, size = 1, shape=8),color = "blue",show.legend=FALSE) +
      scale_shape_identity() +
      scale_colour_continuous(low = "green", high = "red",guide = "colourbar") +  
      transition_time(Hour) +
      scale_alpha(range = c(0,1)) +
      guides(alpha = F) +
      theme_minimal() +
      labs(title = "Date: {frame_time}",x = "Spot Price [EUR]",y = "Price Area") + 
      exit_fade()

Чтобы добавить немного случайных изменений вдоль оси y, вы ' Я хочу использовать geom_jitter (). Попробуйте это:

p <- ggplot() +
          geom_jitter(data = df1, aes(x=SpotPriceEUR, y = PriceArea, colour = SpotPriceEUR,size=2),show.legend=FALSE, width = 0, height = 0.25) +
          geom_point(data = ag, aes(x=ag$x, y = ag$Group.1, size = 1, shape=8),color = "blue",show.legend=FALSE) +
          scale_shape_identity() +
          scale_colour_continuous(low = "green", high = "red",guide = "colourbar") +  
          transition_time(Hour) +
          scale_alpha(range = c(0,1)) +
          guides(alpha = F) +
          theme_minimal() +
          labs(title = "Date: {frame_time}",x = "Spot Price [EUR]",y = "Price Area") + 
          exit_fade()

Возможно, вам придется поиграться с параметром width / height в geom_jitter, чтобы получить именно то, что вам нужно.

...