Posts

Showing posts from April, 2022

How to use patchwork package(Visualization) in R

 library(ggplot2) library(patchwork) p1 <- ggplot(mtcars) +    geom_point(aes(mpg, disp)) +    ggtitle('Plot 1') p1 p2 <- ggplot(mtcars) +    geom_boxplot(aes(gear, disp, group = gear)) +    ggtitle('Plot 2') p2 p3 <- ggplot(mtcars) +    geom_point(aes(hp, wt, colour = mpg)) +    ggtitle('Plot 3') p3 p4 <- ggplot(mtcars) +    geom_bar(aes(gear)) +    facet_wrap(~cyl) +    ggtitle('Plot 4') p4 p1 + p2 p1 + p2 + labs(subtitle = 'This will appear in the last plot') p1 + p2 + p3 + p4 p1 + p2 + p3 + p4 + plot_layout(nrow = 3, byrow = FALSE) p1 / p2 (p1 / p2) | p3 (p1 | (p2 / p3)) +    plot_annotation(title = 'The surprising story about mtcars') p1 + p2 + p3 +    plot_annotation(tag_levels = 'I') library(devtools) library(ggplot2) library(patchwork) d1 <- runif(500) d2 <- rep(c("Treatment","Control"),each=250) d3 <- rbeta(500,shape1=100,shape2=3) d4 <- d3 ...

How to use ggforce(Visualization) Package in R

 library(tidyverse) library(ggforce) library(nycflights13) p <- airports %>%   filter(lon < 0, tzone != "\\N") %>%   ggplot(aes(lon, lat, color = tzone)) +    geom_point(show.legend = FALSE)   p p +   geom_mark_rect()  p +    geom_mark_rect(aes(label = tzone))  p +    geom_mark_rect(aes(label = tzone), show.legend = FALSE) +   theme_void()  p +    geom_mark_hull(aes(label = tzone)) +   theme_void()  p +    geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE) +   theme_void()  p +    geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +   theme_void()  p +    geom_mark_hull(aes(label = tzone, fill = tzone), show.legend = FALSE, expand = unit(3, "mm")) +   theme_no_axes()  p +   facet_zoom(xlim = c(-155, -160.5), ylim = c(19, 22.3)) p +   geom_mark_hul...

Lattice Package implemented in R

 library("lattice") my_data <- iris head(my_data) xyplot(Sepal.Length ~ Petal.Length, data = my_data) xyplot(Sepal.Length ~ Petal.Length, group = Species,         data = my_data, auto.key = TRUE) # Show points ("p"), grids ("g") and smoothing line # Change xlab and ylab xyplot(Sepal.Length ~ Petal.Length, data = my_data,        type = c("p", "g", "smooth"),        xlab = "Miles/(US) gallon", ylab = "Weight (1000 lbs)") xyplot(Sepal.Length ~ Petal.Length | Species,         group = Species, data = my_data,        type = c("p", "smooth"),        scales = "free") # Basic 3D scatter plot cloud(Sepal.Length ~ Sepal.Length * Petal.Width,        data = iris) # Color by groups; auto.key = TRUE to show legend cloud(Sepal.Length ~ Sepal.Length * Petal.Width,        group = Species, data = iris,       auto.ke...

Logistic regression implemented in step by step using R

Image
  What is Logistic Regression? Many a time, situations arise where the dependent variable isn't normally distributed; i.e., the assumption of normality is violated. For example, think of a problem when the dependent variable is binary (Male/Female). Will you still use Multiple Regression? Of course not! Why? We'll look at it below. Let's take a peek into the history of data analysis. So, until 1972, people didn't know how to analyze data which has a non-normal error distribution in the dependent variable. Then, in 1972, came a breakthrough by  John Nelder  and  Robert Wedderburn  in the form of  Generalized Linear Models . I'm sure you would be familiar with the term. Now, let's understand it in detail. Generalized Linear Models are an extension of the linear model framework, which includes dependent variables which are non-normal also. In general, they possess three characteristics: These models comprise a linear combination...