🤩 ggstatsplot | a high color R package that meets your daily statistical needs (IV)
1. Write in front
The point chart is very useful, which can show the distribution of variables, the correlation between variables, regression results, etc
This issue introduces the functions related to plotting DOTPLOT and scatterplot in the ggstatspot package
2. Package used
rm(list=ls()) library(tidyverse) library(ggstatsplot) library(ggsci)
3. Sample data
dat <- mpg
4. dotplot shows sample distribution
4.1 preliminary drawing
The function used is ggscatterstats
Because there are too many factors, we use the filter function here to filter
df <- dplyr::filter(ggplot2::mpg, cyl %in% c("4", "6")) ## Generate enough colors paletter_vector <- paletteer::paletteer_d( palette = "palettetown::venusaur", n = nlevels(as.factor(df$manufacturer)), type = "discrete" ) ## Start drawing ggdotplotstats( data = df, x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", test.value = 15.5, point.args = list( shape = 16, color = paletter_vector, size = 5 ), title = "Distribution of mileage of cars", #ggtheme = ggplot2::theme_dark() )
4.2 complex grouping drawing
The function used is grouped_ggdotplotstats
Let's take a look at the manufacturer distribution of different cyl and cty
Of course, you can also use the purrr package to batch draw. As mentioned in the previous issues,
I won't repeat it here
grouped_ggdotplotstats( ## arguments relevant for ggdotplotstats data = df, grouping.var = cyl, ## grouping variable x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", type = "bayes", ## Bayesian test test.value = 15.5, ## arguments relevant for `combine_plots` annotation.args = list(title = "Fuel economy data"), plotgrid.args = list(nrow = 2) )
5. scatterplot shows the correlation of variables
5.1 preliminary drawing
The function used is ggscatterstats
ggscatterstats( data = dat, x = displ, y = hwy, xlab = "displ", ## label for the x-axis ylab = "hwy", ## label for the y-axis label.var = manufacturer, ## variable to use for labeling data points label.expression = displ > 5 & hwy> 24, ## which points to label point.label.args = list(alpha = 0.7, size = 4, color = "grey50"), xfill = "#CC79A7", ## fill for marginals on the x-axis yfill = "#009E73", ## fill for marginals on the y-axis title = "aaa", caption = "Source" )
5.2 complex grouping drawing
The function used is grouped_ggscatterstats
Let's look at the correlation of hwy of displ of different cLys
Of course, the purrr package also supports batch drawing
grouped_ggscatterstats( ## arguments relevant for ggscatterstats data = df, x = displ, y = hwy, grouping.var = cyl, xlab = "displ", ## label for the x-axis ylab = "hwy", ## label for the y-axis label.var = manufacturer, ## variable to use for labeling data points type = "r", label.expression = displ > 5 & hwy> 24, ## which points to label point.label.args = list(alpha = 0.7, size = 4, color = "grey50"), xfill = "#CC79A7", ## fill for marginals on the x-axis yfill = "#009E73", ## fill for marginals on the y-axis # ggtheme = ggthemes::theme_tufte(), ## arguments relevant for combine_plots annotation.args = list( title = "title", caption = "Source" ), plotgrid.args = list(nrow = 2, ncol = 1) )
Order one and watch it, everyone ~ ✐ ɴɪ ᴄᴇ ᴅᴀ ʏ 〰
[external link image transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-ekfb1p9f-1660733459651)( https://picbed-1312756706.cos.ap-nanjing.myqcloud.com/img/202208170104716.png )]
1. Write in front
The point chart is very useful, which can show the distribution of variables, the correlation between variables, regression results, etc
This issue introduces the functions related to plotting DOTPLOT and scatterplot in the ggstatspot package
2. Package used
rm(list=ls()) library(tidyverse) library(ggstatsplot) library(ggsci)
3. Sample data
dat <- mpg
4. dotplot shows sample distribution
4.1 preliminary drawing
The function used is ggscatterstats
Because there are too many factors, we use the filter function here to filter
df <- dplyr::filter(ggplot2::mpg, cyl %in% c("4", "6")) ## Generate enough colors paletter_vector <- paletteer::paletteer_d( palette = "palettetown::venusaur", n = nlevels(as.factor(df$manufacturer)), type = "discrete" ) ## Start drawing ggdotplotstats( data = df, x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", test.value = 15.5, point.args = list( shape = 16, color = paletter_vector, size = 5 ), title = "Distribution of mileage of cars", #ggtheme = ggplot2::theme_dark() )
4.2 complex grouping drawing
The function used is grouped_ggdotplotstats
Let's take a look at the manufacturer distribution of different cyl and cty
Of course, you can also use the purrr package to batch draw. As mentioned in the previous issues,
I won't repeat it here
grouped_ggdotplotstats( ## arguments relevant for ggdotplotstats data = df, grouping.var = cyl, ## grouping variable x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", type = "bayes", ## Bayesian test test.value = 15.5, ## arguments relevant for `combine_plots` annotation.args = list(title = "Fuel economy data"), plotgrid.args = list(nrow = 2) )
5. scatterplot shows the correlation of variables
5.1 preliminary drawing
The function used is ggscatterstats
ggscatterstats( data = dat, x = displ, y = hwy, xlab = "displ", ## label for the x-axis ylab = "hwy", ## label for the y-axis label.var = manufacturer, ## variable to use for labeling data points label.expression = displ > 5 & hwy> 24, ## which points to label point.label.args = list(alpha = 0.7, size = 4, color = "grey50"), xfill = "#CC79A7", ## fill for marginals on the x-axis yfill = "#009E73", ## fill for marginals on the y-axis title = "aaa", caption = "Source" )
5.2 complex grouping drawing
The function used is grouped_ggscatterstats
Let's look at the correlation of hwy of displ of different cLys
Of course, the purrr package also supports batch drawing
grouped_ggscatterstats( ## arguments relevant for ggscatterstats data = df, x = displ, y = hwy, grouping.var = cyl, xlab = "displ", ## label for the x-axis ylab = "hwy", ## label for the y-axis label.var = manufacturer, ## variable to use for labeling data points type = "r", label.expression = displ > 5 & hwy> 24, ## which points to label point.label.args = list(alpha = 0.7, size = 4, color = "grey50"), xfill = "#CC79A7", ## fill for marginals on the x-axis yfill = "#009E73", ## fill for marginals on the y-axis # ggtheme = ggthemes::theme_tufte(), ## arguments relevant for combine_plots annotation.args = list( title = "title", caption = "Source" ), plotgrid.args = list(nrow = 2, ncol = 1) )
Order one and watch it, everyone ~ ✐ ɴɪ ᴄᴇ ᴅᴀ ʏ 〰
🤩 ggstatsplot | a high color R package that meets your daily statistical needs (IV)
1. Write in front
The point chart is very useful, which can show the distribution of variables, the correlation between variables, regression results, etc
This issue introduces the functions related to plotting DOTPLOT and scatterplot in the ggstatspot package
2. Package used
rm(list=ls()) library(tidyverse) library(ggstatsplot) library(ggsci)
3. Sample data
dat <- mpg
4. dotplot shows sample distribution
4.1 preliminary drawing
The function used is ggscatterstats
Because there are too many factors, we use the filter function here to filter
df <- dplyr::filter(ggplot2::mpg, cyl %in% c("4", "6")) ## Generate enough colors paletter_vector <- paletteer::paletteer_d( palette = "palettetown::venusaur", n = nlevels(as.factor(df$manufacturer)), type = "discrete" ) ## Start drawing ggdotplotstats( data = df, x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", test.value = 15.5, point.args = list( shape = 16, color = paletter_vector, size = 5 ), title = "Distribution of mileage of cars", #ggtheme = ggplot2::theme_dark() )
4.2 complex grouping drawing
The function used is grouped_ggdotplotstats
Let's take a look at the manufacturer distribution of different cyl and cty
Of course, you can also use the purrr package to batch draw. As mentioned in the previous issues,
I won't repeat it here
grouped_ggdotplotstats( ## arguments relevant for ggdotplotstats data = df, grouping.var = cyl, ## grouping variable x = cty, y = manufacturer, xlab = "city miles per gallon", ylab = "car manufacturer", type = "bayes", ## Bayesian test test.value = 15.5, ## arguments relevant for `combine_plots` annotation.args = list(title = "Fuel economy data"), plotgrid.args = list(nrow = 2) )
5. scatterplot shows the correlation of variables
5.1 preliminary drawing
The function used is ggscatterstats
ggscatterstats( data = dat, x = displ, y = hwy, xlab = "displ", ## label for the x-axis ylab = "hwy", ## label for the y-axis label.var = manufacturer, ## variable to use for labeling data points label.expression = displ > 5 & hwy> 24, ## which points to label point.label.args = list(alpha = 0.7, size = 4, color = "grey50"), xfill = "#CC79A7", ## fill for marginals on the x-axis yfill = "#009E73", ## fill for marginals on the y-axis title = "aaa", caption = "Source" )
5.2 complex grouping drawing
The function used is grouped_ggscatterstats
Let's look at the correlation of hwy of displ of different cLys
Of course, the purrr package also supports batch drawing
grouped_ggscatterstats( ## arguments relevant for ggscatterstats data = df, x = displ, y = hwy, grouping.var = cyl, xlab = "displ", ## label for the x-axis ylab = "hwy", ## label for the y-axis label.var = manufacturer, ## variable to use for labeling data points type = "r", label.expression = displ > 5 & hwy> 24, ## which points to label point.label.args = list(alpha = 0.7, size = 4, color = "grey50"), xfill = "#CC79A7", ## fill for marginals on the x-axis yfill = "#009E73", ## fill for marginals on the y-axis # ggtheme = ggthemes::theme_tufte(), ## arguments relevant for combine_plots annotation.args = list( title = "title", caption = "Source" ), plotgrid.args = list(nrow = 2, ncol = 1) )
Order one and watch it, everyone ~ ✐ ɴɪ ᴄᴇ ᴅᴀ ʏ 〰