- Four groups
- 11 observations (x, y) per group
Fall 2016
plot()
generic x-y plottingbarplot()
bar plotsboxplot()
box-and-whisker plothist()
histogramshttp://manuals.bioinformatics.ucr.edu/home/R_BioCondManual#TOC-Some-Great-R-Functions
Weissgerber T et.al., "Beyond Bar and Line Graphs: Time for a New Data Presentation Paradigm", PLOS Biology,2015 http://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.1002128 https://cogtales.wordpress.com/2016/06/06/congratulations-barbarplots/
stats::heatmap()
- basic heatmapAlternatives:
gplots::heatmap.2()
- an extension of heatmapheatmap3::heatmap3()
- another extension of heatmapComplexHeatmap::Heatmap()
- highly customizable, interactive heatmapOther options:
pheatmap::pheatmap()
- grid-based heatmapNMF::aheatmap()
- another grid-based heatmapfheatmap::fheatmap()
- heatmap with some ggplot2gapmap::gapmap()
- gapped heatmap (ggplot2/grid)Interactive heatmaps:
d3heatmap::d3heatmap()
- interactive heatmap in d3heatmaply::heatmaply()
- interactive heatmap with better dendrogramsCompare clusters
dendextend
package - make better dendrograms, compare them with easeqqnorm()
, qqline()
, qqplot()
- distribution comparison plotspairs()
- pair-wise plot of multivariate dataÂ
http://manuals.bioinformatics.ucr.edu/home/R_BioCondManual#TOC-Some-Great-R-Functions
vioplot()
: Violin plot, https://cran.r-project.org/web/packages/vioplot/
PiratePlot()
: violin plot enhanced. install_github("ndphillips/yarrr")
, http://nathanieldphillips.com/
beeswarm()
: The Bee Swarm Plot, an Alternative to Stripchart, https://cran.r-project.org/web/packages/beeswarm/index.html
pdf("filename.pdf", width = 7, height = 5) plot(1:10, 1:10) dev.off()
Other formats: bmp()
, jpg()
, pdf()
, png()
, or tiff()
Learn more ?Devices
https://github.com/nbrgraphs/mro/blob/master/BaseGraphicsCheatsheet.pdf
80% of your work will be data preparation
http://www.gettinggeneticsdone.com/2014/08/do-your-data-janitor-work-like-boss.html
80% of your work will be data preparation
http://www.gettinggeneticsdone.com/2014/08/do-your-data-janitor-work-like-boss.html
https://github.com/hadley/dplyr
install.packages("dplyr")
library(dplyr) library(ggplot2) data(diamonds) head(diamonds) diamonds %>% head summary(diamonds$price) diamonds$price %>% summary(object = .)
diamonds %>% head df.diamonds_ideal <- filter(diamonds, cut == "Ideal") df.diamonds_ideal <- diamonds %>% filter(cut == "Ideal")
df.diamonds_ideal %>% head select(df.diamonds_ideal, carat, cut, color, price, clarity) df.diamonds_ideal <- df.diamonds_ideal %>% select(., carat, cut, color, price, clarity)
df.diamonds_ideal %>% head mutate(df.diamonds_ideal, price_per_carat = price/carat) df.diamonds_ideal <- df.diamonds_ideal %>% mutate(price_per_carat = price/carat)
df.diamonds_ideal %>% head arrange(df.diamonds_ideal, price) df.diamonds_ideal %>% arrange(price, price_per_carat)
summarize(df.diamonds_ideal, length = n(), avg_price = mean(price)) df.diamonds_ideal %>% summarize(length = n(), avg_price = mean(price))
group_by(diamonds, cut) %>% summarize(mean(price)) group_by(diamonds, cut, color) %>% summarize(mean(price))
arrange(mutate(arrange(filter(tbl_df(diamonds), cut == "Ideal"), price), price_per_carat = price/carat), price_per_carat) arrange( mutate( arrange( filter(tbl_df(diamonds), cut == "Ideal"), price), price_per_carat = price/carat), price_per_carat) diamonds %>% filter(cut == "Ideal") %>% arrange(price) %>% mutate(price_per_carat = price/carat) %>% arrange(price_per_carat)
install.packages("ggplot2")
Object | Description | |
---|---|---|
Data | The raw data that you want to plot | |
Aethetics | aes() | How to map your data on x, y axis, color, size, shape (aesthetics) |
Geometries | geom_ | The geometric shapes that will represent the data |
data +
aesthetic mappings of data to plot coordinates +
geometry to represent the data
diamonds %>% filter(cut == "Good", color == "E") %>% ggplot(aes(x = price, y = carat)) + geom_point() # aes(size = price) +
Try other geoms
geom_smooth() # method = lm geom_line() geom_boxplot() geom_bar(stat="identity") geom_histogram()
Parameter | Description | |
---|---|---|
Facets | facet_ | Split one plot into multiple plots based on a grouping variable |
Scales | scale_ | Maps between the data ranges and the dimensions of the plot |
Visual Themes | theme | The overall visual defaults of a plot: background, grids, axe, default typeface, sizes, colors, etc. |
Statistical transformations | stat_ | Statistical summaries of the data that can be plotted, such as quantiles, fitted curves (loess, linear models, etc.), sums etc. |
Coordinate systems | coord_ | Expressing coordinates in a system other than Cartesian |
diamonds %>% # Start with the 'diamonds' dataset filter(cut == "Ideal") %>% # Then, filter rows where cut == Ideal ggplot(aes(price)) + # Then, plot using ggplot geom_histogram() + # and plot histograms facet_wrap(~ color) + # in a 'small multiple' plot, broken out by 'color' ggtitle("Diamond price distribution per color") + labs(x="Price", y="Count") + theme(panel.background = element_rect(fill="lightblue")) + theme(plot.title = element_text(family="Trebuchet MS", size=28, face="bold", hjust=0, color="#777777")) + theme(axis.title.y = element_text(angle=0)) + theme(panel.grid.minor = element_blank())