#Animated Visualization: Chick Weight Variation Over Time by Diet
This code utilizes the ggplot2 package in R to create an animated visualization of the ChickWeight dataset. This code creates an animated plot showing the change in chick weight over time, with each chick represented as a point colored by its diet, and the animation transitioning through time.
library(ggplot2)
library(ggthemes)
library(tidyverse)
library(gganimate)
library(gifski)
library(dplyr)
library(plotly)
chick<-ChickWeight %>%
ggplot(aes(weight, Chick, color=Diet)) +
geom_point() +
labs(title = 'Days: {frame_time}', x = 'Chick weight (grams)', y = 'Chick number') +
#here comes the gganimate code
transition_time(Time) +
ease_aes('linear')+
theme_classic()
chick
#Relationship between GDP per Capita, Life Expectancy, and Population Size Across Countries
This visualization effectively presents the relationship between GDP per capita and life expectancy across different countries, using point size to convey population size and color to distinguish between countries. The log scaling of the x-axis ensures appropriate representation of GDP values, while the Viridis color scale enhances visual perception. Overall, this plot offers valuable insights into the socioeconomic indicators and disparities among various nations.
library(gapminder)
p <- ggplot(gapminder, aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")+
theme_classic()
p
#Geographical Plot: Map of Italy with Polygon Borders
This code generates a geographical plot depicting a map of Italy. It utilizes the map_data() function to obtain data for plotting the borders of Italy. The ggplot() function is then used to create the plot, with geom_polygon() employed to draw the map polygons based on longitude and latitude coordinates. The polygons are outlined in dark color (#03010A) and filled with a greenish color (#31712F). Overall, the plot provides a simple and clear visualization of the geographical boundaries of Italy.
nz<-map_data("italy")
ggplot(nz, aes(long, lat, group=group))+
geom_polygon(col="#03010A", fill="#31712F")