ggplot2

http://ggplot2.tidyverse.org/reference/

theme_set(theme_light())

data visualization analytics datasets business analytics

ggplot2 in r aesthetics colour fill size labels alpha shape geometries point line histogram bar facets columns statistics binning smoothing coordinates cartesian

r ggplot2 data aesthetics geometries facets statistics coordinates theme

big data visualization expert distance work

ggplot aesthetics in r description colour fill size alpha linetype labels shape

Variables in a data frame are mapped to aesthetics in aes(). (e.g. aes(col = cyl)) within ggplot(). Visual elements are set by attributes in specific geom layers (geom_point(col = "red")).

business analytics consultant europe sweden

  • geom_bar(aes(width = prop), stat = “identity”, fill = “skyblue”)
  • ggplot(adult, aes (x = SRAGE_P, fill= factor(RBMI))) +
    geom_histogram(aes(y = ..count../sum(..count..)), binwidth = 1, position = “fill”)

geom_histogram(aes(y = ..count../sum(..count..)), binwidth = 1, position = "fill")

data scientist data analyst expert norway

  • cars %>% ggplot(aes(x = 1, y = msrp)) + geom_boxplot()
  • geom_smooth(aes(color = factor), se = F, lwd = 2)
  • geom_smooth(method = ‘lm’, fullrange = T)
  • geom_smooth(method = “glm”, se = FALSE, method.args = list(family = “binomial”))
    • ‘lm’ =              linear model
    • ‘glm’ =            Generalized Linear Models
    • ‘loess’ =          LOESS
    • span = 0.7
    • geom = ‘path’
    • aes(group = 1, col =’All’) model on all points despite col

machine learning consultant expert

stat_ geom_ stat_bin geom_histogram stat_bin geom_bar stat_bin geon_freqpoly stat_smooth geom_smooth

machine learning data science data scientist ai

  • stat_summary(fun.data = mean_sdl, fun.args = list(mult = 1), position = posn.d)
  • stat_summary(fun.data = mean_cl_normal, position = posn.d)
    • fun.y = mean
    • geom = ‘bar’, ‘errorbar’, ‘ribbon’
    • fun.args =
    • poition = ‘dodge’

predictive analytics predictive analysis programmer

  • + scale_fill_manual(values=c(“#999999”, “#E69F00”, “#56B4E9”))
  • + scale_color_manual(values=c(“#999999”, “#E69F00”, “#56B4E9”))

company data analytics business model consultant

  • coord_trans(x = “log10”, y = “log10”)
  • ggplot(mtcars, aes(1, fill = cyl)) + geom_bar() + coord_polar(theta = “y”)
  • ggplot(mtcars, aes(1, fill = cyl)) + geom_bar(width = 1) + coord_polar()
  • facet_grid(z ~ ., scale = “free_y”, space = “free_y”) leaves out rows with no data.
  • facet_grid(z~w, labeller = label_both)

data analytiker sverige jobba distans maskininlärning

  • theme(legend.position)
  • theme(legend.direction)
  • Theme Layers:
    • text: element_text()
    • line: element_line()
    • rectangle: element_rect()

ggplot2 theme text line rect title plot.title legend.title axis.ticks axis.ticks.y legend.background legend.key

  • + theme(plot.background = element_rect(fill = ‘green’))
  • + theme(plot.background = element_rect(fill = ‘green’, color = ‘black’, size = 3))
  • + theme(plot.background = element_rect(fill = ‘green’, color = ‘black’, size = 3)) + theme(panel.background = element_blank(), legend.key = element_blank(), legend.background=element_blank(), strip.background = element_blank())
  • + theme(panel.grid = element_blank(), axis.line = element_line(color = “black”),
    axis.ticks = element_line(color = “black”))
  • + theme(strip.text = element_text(size = 16, color = myRed),
    axis.title.y = element_text(color = ‘red’, hjust = 0, face = “italic”),
    axis.title.x = element_text(color = ‘red’, hjust = 0, face = “italic”),
    axis.text = element_text(color = “black”))
  • + theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 0.1))
  • theme_update(): updates general theme,  
  • theme_set()

ggplot geom_recta

library(grid) increase spacing between facets

brewer.pal()

+ scale_fill_brewer(palette = “OrRd”)

p5 = ggplot(lastbalans, aes(time)) + geom_bar() + xlim(c(0.3,2.5)) + ggtitle(“totalt”)
p6 = ggplot(appdf, aes(time)) + geom_bar() + xlim(c(6.5,7.5)) + ggtitle(“totalt”)
grid.arrange(p3, p4, ncol=2)