Not quite, mainly because so many other libraries have covered this quite well. Let’s look at some examples:
Using Base-R
read_csv("us-states.csv")
states <-%>% select(cases, deaths) %>% summary()
states
cases deaths : 1 Min. : 0
Min. : 10205 1st Qu.: 233
1st Qu.: 78464 Median : 1570
Median : 248857 Mean : 5022
Mean : 304485 3rd Qu.: 5906
3rd Qu.:3795820 Max. :63544 Max.
psych
packagelibrary(psych)
%>% select(cases, deaths) %>% psych::describe()
states
vars n mean sd median trimmed mad min max1 25369 248857.2 459490.12 78464 147409.31 113596.81 1 3795820
cases 2 25369 5022.3 8748.31 1570 2944.01 2286.17 0 63544
deaths
range skew kurtosis se3795819 4.07 21.58 2884.86
cases 63544 3.27 12.93 54.93 deaths
Hmisc
package%>% select(cases, deaths) %>% Hmisc::describe()
states
.
2 Variables 25369 Observations
--------------------------------------------------------------------------------
cases .05 .10
n missing distinct Info Mean Gmd 25369 0 21528 1 248857 354122 82.4 896.8
.25 .50 .75 .90 .95
10205.0 78464.0 304485.0 665750.6 987267.6
: 1 2 3 4 5
lowest : 3791972 3793055 3794235 3795063 3795820
highest--------------------------------------------------------------------------------
deaths .05 .10
n missing distinct Info Mean Gmd 25369 0 9545 1 5022 7115 2 16
.25 .50 .75 .90 .95
233 1570 5906 14179 22162
: 0 1 2 3 4, highest: 63287 63345 63393 63423 63544
lowest --------------------------------------------------------------------------------
ggplot2
can draw individual plots but in order to put many plots together in a multi-panel figure, we need to rely on external libraries. Here are a couple of examples. First let’s make some individual plots. states %>% filter(state == "California") %>% ggplot() + geom_histogram(aes(x=cases))
plot1 <-
states %>% filter(state == "California") %>% ggplot() + geom_histogram(aes(x=deaths))
plot2 <-
states %>% filter(state == "California") %>% ggplot() + geom_point(aes(x=cases, y=deaths)) plot3 <-
Now get the following libraries:
ggpubr
, cowplot
ggpubr
library(ggpubr)
ggarrange(plot1, plot2, plot3, labels=c("Cases", "Deaths", "Relationship"), ncol=3, nrow=1)
ggsave("combined_ggarrange.pdf")
cowplot
library(cowplot)
plot_grid(plot1, plot2, plot3, labels=c("Cases", "Deaths", "Relationship"), ncol=3, nrow=1)
ggsave("combined_cowplot.pdf")
Load iris
, a built in data set in R.
Using psych
package, calculate summary statistics on only the numerical data portion in iris
Create four histograms for each of the four numerical variables and store them into R objects
Using the ggpubr
package, create a multi panel plot and use ggsave
to write it to a file.