theme_set(theme_excel())
data(iris)

Scatter plot

ggplot(data = iris) +
  aes(x = Sepal.Length, y = Sepal.Width, colour = Species) +
  geom_point(size = 3, shape = 16)

Histogram

res <- sample(1:100, 10)

res
##  [1] 55 18 68 88 97 82 58  5 73 79
sum(res)
## [1] 623

The total of the two numbers is 623.

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, colour = Species), binwidth = 0.5, fill = "black", col = "white")

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length), binwidth = 0.5, fill = "lightblue", col = "white")

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, fill = Species), bins = 10, col = "white", alpha = 0.7)

Reduce gap

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, fill = Species), bins = 20, col = "white", alpha = 0.6) +
  coord_cartesian(expand = FALSE) +
  scale_y_continuous(
    breaks = seq(-10, 30, by = 2),
    expand = expansion(
      mult = c(-10, 10),
      add = c(10, 0)
    )
  )

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, fill = Species), bins = 20, col = "white", alpha = 0.6) +
  scale_y_continuous(expand = expansion(add = c(0, 5))) +
  scale_x_continuous(expand = expansion(add = c(2, 0)))

Facet

facet wrap

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, fill = Species), bins = 10, col = "white", alpha = 0.6) +
  facet_wrap(vars(Species), ncol = 1, scales = "free_x")

facet gread

ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, fill = Species), col = "white", bins = 10, alpha = 0.6) +
  coord_cartesian(expand = FALSE) +
  facet_grid(rows = vars(Species), scales = "free_y")

Loading Student Data

student <- read_excel("data/StudentSurveyData.xlsx")
student
## # A tibble: 111 × 15
##       ID Gender   Age Class     Major   `Grad Intention`   GPA Employment Salary
##    <dbl> <chr>  <dbl> <chr>     <chr>   <chr>            <dbl> <chr>       <dbl>
##  1     1 Female    20 Sophomore Other   Yes               2.88 Full-Time    55  
##  2     2 Male      23 Senior    Manage… Yes               3.6  Part-Time    30  
##  3     3 Male      21 Freshman  Other   Yes               2.5  Part-Time    50  
##  4     4 Male      21 Sophomore IS      Yes               2.5  Full-Time    45  
##  5     5 Male      23 Senior    Other   Undecided         2.8  Unemployed   45  
##  6     6 Female    26 Senior    Econom… Undecided         2.34 Unemployed   83  
##  7     7 Female    21 Junior    Other   Undecided         3    Part-Time    55  
##  8     8 Female    30 Senior    Other   Undecided         3.1  Full-Time    85  
##  9     9 Female    20 Sophomore Manage… Yes               3.6  Unemployed   35  
## 10    10 Female    21 Senior    Econom… Undecided         3.3  Part-Time    42.5
## # ℹ 101 more rows
## # ℹ 6 more variables: `Social Networking` <dbl>, Satisfaction <dbl>,
## #   Spending <dbl>, Computer <chr>, `Text Messages` <dbl>, Wealth <dbl>
ggplot(data = student) +
  geom_histogram(aes(x = GPA, fill = Gender), col = "white", bins = 25) +
  coord_cartesian(expand = FALSE) +
  scale_x_continuous(breaks = seq(2, 4, 0.1))

student %>%
  filter(GPA <= 3 & Gender == "Female") %>%
  summarise(total = n())
## # A tibble: 1 × 1
##   total
##   <int>
## 1    22
ggplot(data = student) +
  geom_histogram(aes(x = GPA, fill = Employment), col = "white", bins = 10, alpha = 0.5) +
  coord_cartesian(expand = FALSE) +
  facet_grid(rows = vars(Employment), cols = vars(Class))

student %>%
  mutate(Class = factor(Class, levels = c("Freshman", "Sophomore", "Junior", "Senior"))) %>%
  ggplot() +
  geom_histogram(aes(x = GPA, fill = Employment), bins = 10, col = "white", alpha = 0.5) +
  facet_grid(rows = vars(Employment), cols = vars(Class))

#them

ggplot(data = student)+
  geom_histogram(aes(x = GPA,fill = Employment),bins = 10,col = "white")+facet_wrap(vars(Employment),ncol(1))+theme_bw()

thems cor packeges

p1<-ggplot(data = student)+
  geom_histogram(aes(x = GPA,fill = Employment),bins = 10,col = "white")+facet_wrap(vars(Employment),ncol(1))+theme_base()
p2<-ggplot(data = iris) +
  geom_histogram(aes(x = Sepal.Length, fill = Species), bins = 10, col = "white", alpha = 0.6) +
  facet_wrap(vars(Species), ncol = 1, scales = "free_x")


p2<-p2+labs(
  title = "Histogram of the dataset",
  x = "sepal Length",
  y = "Friquency",
  file = "specis",
  subtitle = "using facet and other Customaization",
  caption = "data:IRIS"
)
p2

#ggThemeAssistGadget(p2)

p2 + theme(plot.background = element_rect(fill = "aquamarine1")) + theme(axis.text = element_text(family = "Times"),
    panel.background = element_rect(fill = NA,
        linetype = "dotted"), plot.background = element_rect(fill = "antiquewhite2",
        colour = NA, linetype = "dotted"))+scale_fill_manual(values = c("setosa"="#30A19C","virginica"="#ff138C","versicolor"="#1Af"))+coord_cartesian(expand = F)+scale_fill_hue(l = 20,c =150,h = c(90,360))
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.