0 votes
in R Language by
Bivariate analysis with ggpair with grouping in R Language

1 Answer

0 votes
by

The next graph plots three information:

  • The correlation matrix between log_totexp, log_income, age and wtrans variable grouped by whether the household has a kid or not.
  • Plot the distribution of each variable by group
  • Display the scatter plot with the trend by group
library(ggplot2)
ggpairs(data, columns = c("log_totexp", "log_income", "age", "wtrans"), title = "Bivariate analysis of revenue expenditure by the British household", upper = list(continuous = wrap("cor",
        size = 3)),
    lower = list(continuous = wrap("smooth",
        alpha = 0.3,
        size = 0.1)),
    mapping = aes(color = children_fac))
  • columns = c("log_totexp", "log_income", "age", "wtrans"): Choose the variables to show in the graph
  • title = "Bivariate analysis of revenue expenditure by the British household": Add a title
  • upper = list(): Control the upper part of the graph. I.e. Above the diagonal
  • continuous = wrap("cor", size = 3)): Compute the coefficient of correlation. We wrap the argument continuous inside the wrap() function to control for the aesthetic of the graph ( i.e. size = 3) -lower = list(): Control the lower part of the graph. I.e. Below the diagonal.
  • continuous = wrap("smooth",alpha = 0.3,size=0.1): Add a scatter plot with a linear trend. We wrap the argument continuous inside the wrap() function to control for the aesthetic of the graph ( i.e. size=0.1, alpha=0.3)
  • mapping = aes(color = children_fac): We want each part of the graph to be stacked by the variable children_fac, which is a categorical variable taking the value of 1 if the household does not have kids and 2 otherwise

Related questions

0 votes
asked Nov 14, 2019 in R Language by MBarbieri
0 votes
asked Nov 14, 2019 in R Language by MBarbieri
...