Workshop Sarah Pendergrass, PhD MS Research Associate

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Introduction to Formatting VistaPHw Charts Brought to you by: The Vista Partnership February 2007.
Basics of Biostatistics for Health Research Session 2 – February 14 th, 2013 Dr. Scott Patten, Professor of Epidemiology Department of Community Health.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
Copyright © 2014 Pearson Education, Inc. All rights reserved Chapter 2 Picturing Variation with Graphs.
Workshop Sarah Pendergrass, PhD MS Research Associate Center for Systems Genomics.
Plotting with ggplot2: Part 1
Excel Charts – Basic Skills Creating Charts in Excel.
Creating a Histogram using the Histogram Function.
Reading Graphs and Charts are more attractive and easy to understand than tables enable the reader to ‘see’ patterns in the data are easy to use for comparisons.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
Checking the Required Conditions. Check these 3 boxes.
Web Page Development Identify elements of a Web Page Start Notepad
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a Message.
1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a Message Robert Grauer and Maryann Barber Exploring.
COMPREHENSIVE Excel Tutorial 4 Working with Charts and Graphics.
1 Computing for Todays Lecture 10 Yumei Huo Fall 2006.
Introduction to Computer Graphics
Using Charts in a Presentation Lesson 6. Software Orientation Charts can help your audience understand relationships among numerical values. The figure.
XP New Perspectives on Microsoft Office Excel 2003 Tutorial 4 1 Microsoft Office Excel 2003 Tutorial 4 – Working With Charts and Graphics.
PowerPoint Lesson 3 Working with Visual Elements
NU Data Excel Orientation Graphing of Screening Data and Basic Graphing Functions.
Pasewark & Pasewark 1 Word Lesson 6 Working with Graphics Microsoft Office 2007: Introductory.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week5: Charts/Plots in R.
Microsoft Office 2007: Introductory 1 Word Lesson 6 Working with Graphics Computer Applications 1.
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
11 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Baburao Kamble (Ph.D) University of Nebraska-Lincoln
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
OPL MRR Viewer Tutorial David Stark North Carolina State University 31 Jan 2008.
XP Mohammad Moizuddin Creating Web Pages with HTML Tutorial 1 1 New Perspectives on Creating Web Pages With HTML Tutorial 1: Developing a Basic Web Page.
Quantitative Skills 1: Graphing
Exploring Excel 2003 Revised - Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a.
Chapter 9 Creating and Designing Graphs. Creating a Graph A graph is a diagram of data that shows relationship among a set of numbers. Data can be represented.
A Picture Is Worth A Thousand Words. DAY 7: EXCEL CHAPTER 4 Tazin Afrin September 10,
Microsoft ® Office Excel 2007 Working with Charts.
Dot Plots and Histograms Lesson After completing this lesson, you will be able to say: I can create a dot plot and histogram to display a set of.
An Internet of Things: People, Processes, and Products in the Spotfire Cloud Library Dr. Brand Niemann Director and Senior Data Scientist/Data Journalist.
Section 8.1 Create a custom theme Design a color scheme Use shared borders Section 8.2 Identify types of graphics Identify and compare graphic formats.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
CTS130 Spreadsheet Lesson 9 - Building Charts. What is a Chart? A chart is a visual display of information in a worksheet. Charts can help you make comparisons,
1. Chapter 15 Creating Charts 3 Charting Data in Word A chart or graph presents data visually. A chart depicts numeric data in a graphical format. If.
Adobe InDesign CS2—Revealed PLACING AND LINKING GRAPHICS.
Using Google Sheets To help with data. Sheets is a spreadsheet program that can interface with Docs, or Slides A spreadsheet program has cells (little.
PLACING AND LINKING GRAPHICS
Ggplot2 A cool way for creating plots in R Maria Novosolov.
Introduction to Graphics in R 3/12/2014. First, let’s get some data Load the Duncan dataset It’s in the car package. Remember how to get it? – library(car)
Key Applications Module Lesson 14 — Working with Tables Computer Literacy BASICS.
Outline Research Question: What determines height? Data Input Look at One Variable Compare Two Variables Children’s Height and Parents Height Children’s.
Creating Charts Ms. Hall Spring Using the Insert Tab to Create Charts The Insert tab contains the command groups you’ll use to create charts in.
Frequency Distributions Chapter 2. Descriptive Statistics Distributions are part of descriptive statistics…we are learning how to describe some data by.
HTML5 and CSS3 Illustrated Unit F: Inserting and Working with Images.
Section 8.1 Section 8.2 Create a custom theme Design a color scheme
How to use Microsoft PowerPoint
EMPA Statistical Analysis
Overview of R and ggplot2 for graphics
Layers in Adobe After Effect
Charts & Graphs CTEC V
Using R Graphs in R.
Inserting and Working with Images
Introduction to R Studio
QM222 A1 Visualizing data using Excel graphs
Enhancing a Document Part 1
Enhancing a Document Part 1
INTRODUCTION TO SGPLOT Zahir Raihan OVERVIEW  ODS Graphics  SGPLOT overview  Plot Content  High value plot statements  High value plot options 
Introduction to PowerPoint
Overview of R and ggplot2 for graphics
DATA VISUALISATION (QUANTITATIVE).
Presentation transcript:

Workshop Sarah Pendergrass, PhD MS Research Associate Center for Systems Genomics

Outline ggplot2 Cytoscape PhenoGram

ggplot2 ggplot2 Plotting system for R Flexible, accessible, visualization of data You must have R installed You must have ggplot2 installed: install.packages("ggplot2") library(ggplot2)

ggplot2 ggplot2 Developed by Hadley Wickham Grammar of graphics: formal structured perspective on describing data graphics Data properties: typically numerical or categorical values Visual properties: x and y positions of points, colors of lines, heights of bars Once you have your code you can reuse reuse reuse Benefits compared to other R packages Structure of the data can remain the same while making very different types of plots Standard format for generating plots

ggplot2 ggplot2 Plotting system for R Flexible, accessible, visualization of data We will walk through some examples, great references: “R Graphics Cookbook” “ggplot2” by Hadley Wickham Many more examples also exist on-line Worth doing image searches when you have a new set of data to plot to get ideas and basic code to modify

ggplot2 Input/Output Windows: Mac: A little about file input Input – a dataframe data <- read.table (“datafile.txt”,header=TRUE) data <- read.csv(“datafile.txt”, header=FALSE) There are also commands for importing excel spread sheets Windows: windows()will open a new figure window Mac: quartz()will open a new figure window

ggplot2 Input/Output A little about file output Raster/bitmap Array of pixels Can go high resolution (ex 600 dpi) Vector Infinitely “zoomable” Can be modified more easily in Adobe Illustrator Slow to render with thousands of graphical objects ggsave(file = “output.pdf”) Or pdf(file = “output.pdf”) Then ggplot command dev.off() Raster: png(),jpeg(),bitmap(),tiff() Vector: pdf(),ps()

ggplot2 Input/Output A little about file output Illustrator: svg Latex: ps MS Office: png (600 dpi) Open Office: png (600 dpi) Pdflatex: pdf, png (600 dpi) Web: png (72 dpi) Or whatever your journal specifies! Can specify dpi by adding to the command ggsave(file = “output.png”, dpi=600)

ggplot2 vocabulary Data: what we want to visualize Consisting of variables in a data frame Data frame: primary data structure in R with properties of matrices Geoms: geometric objects drawn to represent the data Aesthetics (aes): visual properties of geoms such as defining X, defining Y, line color, point shapes, etc. Mappings: mapping from data values to aesthetics Scales: control mapping from data space to aesthetic space Guides: show viewer how to map visual properties back to data space: tick marks and labels, etc

ggplot2 basics ggplot2 Data has to be saved in a data frame Each type of variable mapped to an aesthetic must be stored in a separate column (your x, y variables) Basic ggplot2 specification: ggplot(dat, aes(x=xval, y=yval) x=xval maps the column xval to the x position y=yval maps the column yval to the y position Now you need to add geometric objects… let’s go make a first plot!

ggplot2 Example 1: Scatter Plot Load example data frame 1: dat <- read.table ("datafile.txt",header=FALSE,sep="\t") Name the columns: names(dat) <-c("SampleID","PC1","PC2","Ancestry","Site","Platform","Sex","BMI") Type dat to check your data frame and remember, up and down arrows are your friend in R!

ggplot2 Example 1: Scatter Plot Type dat to check your data frame

ggplot2 Example 1: Scatter Plot ggplot(dat, aes (x=PC1, y=PC2)) Indicates the data (our data frame) xval column values are mapped to the x position, etc. But we need to add geometric objects such as points, so we need to add: Command: ggplot(dat,aes(x=PC1,y=PC2))+geom_point() We can add group to the color of the points, by adding specifying aesthetics for that particular geom ggplot(dat,aes(x=PC1,y=PC2)) + geom_point(aes(color=Ancestry)) And if you want ggsave(file="output1.pdf")

ggplot2 Example 1: Scatter Plot

ggplot2 Example 1: Scatter Plot Command: ggplot(dat,aes(x=PC1, y=PC2))+geom_point() We can add group to the color of the points, by adding specifying aesthetics for that particular geom last_plot()+geom_point(aes(color=Ancestry))

ggplot2 Example 1: Scatter Plot

ggplot2 Example 1: Scatter Plot How about changing the axes? Command: ggplot(dat,aes(x=PC1,y=PC2))+geom_point() Modify the scale: ggplot(dat,aes(x=PC1,y=PC2))+geom_point() + scale_x_continuous(limits=c(0,8))

ggplot2 Example 1: Scatter Plot Change points ggplot(dat,aes(x=PC1,y=PC2,color=Ancestry)) + geom_point(shape=1)+scale_colour_hue(l=50) # Open circles and a slightly darker palette than normal Add regression lines ggplot(dat,aes(x=PC1,y=PC2)) + geom_point(shape=1)+scale_colour_hue(l=50) + geom_smooth(method=lm,se=FALSE) #Add linear regression lines but don’t add shaded confidence region ggplot(dat,aes(x=PC1,y=PC2,color=Ancestry)) + geom_point(shape=1) + scale_colour_hue(l=50) + geom_smooth(method=lm,se=FALSE)

ggplot2 Example 1: Scatter Plot

ggplot2 Example 1: Scatter Plot Set shape based on a condition ggplot(dat,aes(x=PC1,y=PC2,shape=Ancestry)) + geom_point() Set shape and color based on separate conditions ggplot(dat,aes(x=PC1, y=PC2, color=Platform,shape=Ancestry)) + geom_point() Same but use hollow circles and triangles ggplot(dat,aes(x=PC1,y=PC2,shape=Ancestry, color=Platform)) + geom_point() + scale_shape_manual(values=c(1,2))

ggplot2 Example 1: Scatter Plot

ggplot2 Example 1: Scatter Plot Same but increase shape size and text size theme_set(theme_gray(base_size = 15)) ggplot(dat,aes(x=PC1,y=PC2,shape=Ancestry, color=Platform)) + geom_point(size=8)

ggplot2 Example 2: Histograms ggplot(dat, aes(x=BMI)) + geom_histogram(binwidth=.5, colour="black", fill="white") Histogram adding the mean ggplot(dat, aes(x=BMI)) + geom_histogram(binwidth=.5, colour="black", fill="white") +geom_vline(aes(xintercept=mean(BMI, na.rm=T)),color="red", linetype="dashed", size=1) Tip: you can use “bin width” to adjust bin size (wider bins, more items in each bin) ggplot(dat, aes(x=BMI)) + geom_histogram(binwidth=5, colour="black", fill="white") +geom_vline(aes(xintercept=mean(BMI, na.rm=T)),color="red", linetype="dashed", size=1)

ggplot2 Example 2: Histogram and Density Graphs

ggplot2 Example 4: Bar Graph Making a bar graph: ggplot(data=dat, aes(x=SampleID, y=BMI))+ geom_bar(stat="identity") Colors ggplot(data=dat, aes(x=SampleID, y=BMI, fill=Ancestry))+ geom_bar(stat="identity")

Ggplot2: Bar Graph The space below the top line on a bar chart is usually meaningless – only representing the distance between start value and plotted value The information of the bar plot can actually be represented with single dots This can cut down on visual clutter, and also make a more visually meaningful plot One way to show the trends of the points – but needs more: ggplot(data=dat, aes(x=SampleID, y=BMI))+ geom_point()

Ggplot2: Bar Graph One way to show the trends of the points better – however this might make it seem like nearby points are related via proximity ggplot(data=dat, aes(x=SampleID, y=BMI))+ geom_line()+geom_point()

Ggplot2: Cleveland Dot Plot Another way to show the trends of the points better: Cleveland Dot Plot ggplot(data=dat, aes(x=SampleID, y=BMI))+geom_segment(aes(xend=SampleID),yend=0,color="grey") + geom_point()

ggplot2 Example 5: Creating Boxplots When comparing the distributions of groups of data, boxplots are a great approach instead of bar charts Command: ggplot(dat,aes(x=Sex,y=BMI)) + geom_boxplot()

ggplot2 Example 5: Creating Boxplots When comparing the distributions of groups of data, boxplots are a great approach instead of bar charts Adding color to box plot ggplot(dat,aes(x=Sex,y=BMI,fill=Sex)) + geom_boxplot()

ggplot2 Example 5: Creating Boxplots When comparing the distributions of groups of data, boxplots are a great approach instead of bar charts Add summary like mean to box plot (Adding mean as a diamond shape) ggplot(dat,aes(x=Sex,y=BMI)) + geom_boxplot()+ stat_summary(fun.y=mean,geom="point", shape=5, size=4)

ggplot2 Example 5: Creating Boxplots When comparing the distributions of groups of data, boxplots are a great approach instead of bar charts Adding individual data points to the box plot ggplot(dat, aes(x=Sex,y=BMI,fill=Sex)) + geom_boxplot()+geom_point()

ggplot2 Example 5: Creating Boxplots When comparing the distributions of groups of data, boxplots are a great approach instead of bar charts What about adding a title? ggplot(dat,aes(x=Sex,y=BMI,fill=Sex)) + geom_boxplot()+geom_point()+ggtitle("BMI for each Sex")

ggplot2 Example 5: Creating Boxplots When comparing the distributions of groups of data, boxplots are a great approach instead of bar charts What about adding modifying the axis titles? ggplot(dat, aes(x=Sex, y=BMI,fill=Sex)) + geom_boxplot() +geom_point()+ggtitle("BMI for each Sex")+xlab("Sex")+ylab("Body Mass Index")

ggplot2 Example 6:Facets You to split up your data by one or more variables and plot the subsets of data together: ggplot(dat,aes(x=PC1,y=PC2)) + geom_point(aes(color=Ancestry))+facet_grid(Sex ~ .)

ggplot2 A Note on Colors In the examples, we used mostly ggplot2 default colors There are lots of options for getting into different colors for ggplot2 http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ Example Using scale_fill_manual, you can use color hexadecimal codes (you can get these from Color Brewer http://colorbrewer2.org/) ggplot(dat,aes(x=Sex,y=BMI,fill=Sex))+geom_bar(stat="identity") +scale_fill_manual(values=c("#CC6666","#9999CC"))

ggplot2 Other Notes Not covered here but so many options! Color of background Grid line modification Font choice Other kinds of plots such as heatmaps, and using the techniques here to make Manhattan plots, coloring maps with information

ggplot2 Other Notes Examples and code are EVERYWHERE!! This was just a Google Image search on “ggplot2”!

Cytoscape Introduction to Cytoscape

PhenoGram Chromosomal Ideogram Can add lines, shapes, and text Can add cytogenetic banding patterns Web version here: http://visualization.ritchielab.psu.edu/phenograms/plot Example files here: http://visualization.ritchielab.psu.edu/phenograms/examples Currently only human chromosomal information, adding mouse soon and will add other model organisms

PhenoGram Chromosomal Ideogram Can add lines, shapes Can add cytogenetic banding patterns Download: phenogram-groups-sample.txt Go to: http://visualization.ritchielab.psu.edu/phenograms/plot

PhenoGram

PhenoGram Chromosomal Ideogram Can plot just lines Download: phenogram-groups-poscolor.txt Go to: http://visualization.ritchielab.psu.edu/phenograms/plot