202AIE35

차밝음


Problem 1


library(ggplot2)

ggplot(
  data = mpg,
  aes(x = hwy, fill = drv)
) + 
geom_histogram(alpha= 0.5) + 
labs(
  title = "Histogram",
  subtitle = "Histogram of Highway Mile Per Gallon",
  caption = "Source : mpg"
)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Problem 2


ggplot(
  data = mpg,
  aes(hwy, fill = drv)
) + 
geom_histogram(alpha = 0.5) +
facet_grid(rows =vars(drv)) +  
labs( 
  title = "Histogram using facet_grid()",
  subtitle = "Histogram of Highway Mile Per Gallon",
  caption = "Source : mpg"
) +
theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Problem3


ggplot(
  data = midwest, 
  aes(x = area, y = poptotal)
) + 
geom_point(
  aes(color = state, size = popdensity),
  alpha = 0.4
) +
geom_smooth(se = FALSE) +
labs(
  title = "Scatterplot",
  subtitle =  "Area Vs Population",
  caption = "Source : midwest",
  x = "Area",
  y = "Population"
) + xlim(0,0.100) + ylim(0,50000) + theme_classic()  
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 154 rows containing non-finite values (stat_smooth).
## Warning: Removed 154 rows containing missing values (geom_point).

Problem 4


ggplot(
  data = iris,
  aes(x = Sepal.Length, y = Sepal.Width)
) +
geom_point(
  aes(color = Species, shape = Species),
  alpha = 0.5,
  size = 6
) + 
labs(
  title = "Scatterplot",
  subtitle = "Sepal.Length Vs Sepal.Width",
  caption = "Source : iris"
) +
theme_minimal()

Problem 5


library(gcookbook)

ggplot(
  data = heightweight, 
  aes(x = heightIn, y = weightLb, color = sex)
) + 
geom_point(alpha = 0.5, size = 3) +  
geom_quantile(quantiles=0.5) +
theme_classic()
## Smoothing formula not specified. Using: y ~ x
## Smoothing formula not specified. Using: y ~ x

Problem 6


ggplot(
  data = mpg,
  aes( x= manufacturer, fill = class)
) + 
geom_bar(width = 0.5)+ scale_fill_brewer(palette = "Spectral") +
labs(
  title = "Barplot",
  subtitle = "Manufacturer across Vehicle Classes"
) + 
theme(axis.text.x=element_text(angle =65, vjust = 0.5))