Exercises: Plotting Complex Figures Using R

Similar documents
Lesson 4 Advanced Transforms

Chapter 2 Basic Operations

Adverse Action Letters

INSTALLING CCRQINVOICE

TRAINING GUIDE. Overview of Lucity Spatial

Test Pilot User Guide

Lab 4. Name: Checked: Objectives:

Simple Regression in Minitab 1

Using the Swiftpage Connect List Manager

Using the Swiftpage Connect List Manager

ClassFlow Administrator User Guide

Network Rail ARMS - Asbestos Risk Management System. Training Guide for use of the Import Asset Template

LAB 7 (June 29/July 4) Structures, Stream I/O, Self-referential structures (Linked list) in C

The Reporting Tool. An Overview of HHAeXchange s Reporting Tool

CREATING A DONOR ACCOUNT

Relius Documents ASP Checklist Entry

Getting Started with the Web Designer Suite

Reporting Requirements Specification

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture2 Functions

Tutorial 5: Statistical analysis of DIA data

$ARCSIGHT_HOME/current/user/agent/map. The files are named in sequential order such as:

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2

Scroll down to New and another menu will appear. Select Folder and a new

Proper Document Usage and Document Distribution. TIP! How to Use the Guide. Managing the News Page

Data Miner Platinum. DataMinerPlatinum allows you to build custom reports with advanced queries. Reports > DataMinerPlatinum

Web of Science Institutional authored and cited papers

Adobe InDesign: The Knowledge

Using SPLAY Tree s for state-full packet classification

Word 2007 The Ribbon, the Mini toolbar, and the Quick Access Toolbar

TUTORIAL --- Learning About Your efolio Space

Renewal Reminder. User Guide. Copyright 2009 Data Springs Inc. All rights reserved.

1 Version Spaces. CS 478 Homework 1 SOLUTION

Procurement Contract Portal. User Guide

MySqlWorkbench Tutorial: Creating Related Database Tables

Quick start guide: Working in Transit NXT with a PPF

Asset Panda Web Application Release 12.02

Automatic imposition version 5

STUDIO DESIGNER. Design Projects Basic Participant

Student Guide. Where can I print? Charges for Printing & Copying. Top up your Print Credits Online, whenever you like

Network Rail ARMS - Asbestos Risk Management System. Training Guide for use of the Import Survey Template

Once the Address Verification process is activated, the process can be accessed by employees in one of two ways:

Lab 5 Sorting with Linked Lists

OpenSceneGraph Tutorial

Integrating QuickBooks with TimePro

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2 Iterative Code Design handout Style Guidelines handout

What s New in Banner 9 Admin Pages: Differences from Banner 8 INB Forms

PAGE NAMING STRATEGIES

Exercise 4: Working with tabular data Exploring infant mortality in the 1900s

How to use DCI Contract Alerts

RISKMAN REFERENCE GUIDE TO USER MANAGEMENT (Non-Network Logins)

Tutorial 5: Statistical analysis of DIA data

SAS Viya 3.2 Administration: Mobile Devices

IBM Cognos TM1 Web Tips and Techniques

QUICK START GUIDE FOR THE TREB CONNECT INTERFACE

TaiRox Mail Merge. Running Mail Merge

BI Publisher TEMPLATE Tutorial

STIQuery Basics. A second example is included at the end of this document.

COP2800 Homework #3 Assignment Spring 2013

Qualtrics Instructions

The Login Page Designer

Creating a TES Encounter/Transaction Entry Batch

TRAINING GUIDE. Lucity Mobile

Access 2000 Queries Tips & Techniques

Faculty Textbook Adoption Instructions

Case Metrics Guide. January 11, 2019 Version For the most recent version of this document, visit our documentation website.

Homework: Populate and Extract Data from Your Database

Tutorial 5: Retention time scheduling

Entering an NSERC CCV: Step by Step

LAB 0 MATLAB INTRODUCTION

Focus University Training Document

Introduction to GRIN Global Curator Tool Interface

These tasks can now be performed by a special program called FTP clients.

Support Subscribers call

Reading and writing data in files

Transforming Quadratic Functions Day 2

What s New in version 3.04 November 2012

Gmail and Google Drive for Rutherford County Master Gardeners


INSERTING MEDIA AND OBJECTS

Constituent Page Upgrade Utility for Blackbaud CRM

MOS Access 2013 Quick Reference

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Communication Tools. Quick Reference Card. Communication Tools. Mailing Labels. 6. For the Label Content, follow these rules:

FAQ. Using the Thinkific Learning Platform

CLIC ADMIN USER S GUIDE

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

Australian Statistics API Specification

ClubRunner. Volunteers Module Guide

Aras Innovator Viewer Add-Ons

1 Binary Trees and Adaptive Data Compression

ROCK-POND REPORTING 2.1

Assignment #5: Rootkit. ECE 650 Fall 2018

UBC BLOGS NSYNC PLUGIN

Preparation: Follow the instructions on the course website to install Java JDK and jgrasp on your laptop.

Mooring system design in anysim. Introduction... 2

Iteration Part 2. Review: Iteration [Part 1] Flow charts for two loop constructs. Review: Syntax of loops. while continuation_condition : statement1

Extended Vendors lets you: Maintain vendors across multiple Sage 300 companies using the Copy Vendors functionality. o

Chapter 1 Getting Started

Please contact technical support if you have questions about the directory that your organization uses for user management.

Transcription:

Exercises: Pltting Cmplex Figures Using R Versin 2017-11

Exercises: Pltting Cmplex Figures in R 2 Licence This manual is 2016-17, Simn Andrews. This manual is distributed under the creative cmmns Attributin-Nn-Cmmercial-Share Alike 2.0 licence. This means that yu are free: t cpy, distribute, display, and perfrm the wrk t make derivative wrks Under the fllwing cnditins: Attributin. Yu must give the riginal authr credit. Nn-Cmmercial. Yu may nt use this wrk fr cmmercial purpses. Share Alike. If yu alter, transfrm, r build upn this wrk, yu may distribute the resulting wrk nly under a licence identical t this ne. Please nte that: Fr any reuse r distributin, yu must make clear t thers the licence terms f this wrk. Any f these cnditins can be waived if yu get permissin frm the cpyright hlder. Nthing in this license impairs r restricts the authr's mral rights. Full details f this licence can be fund at http://creativecmmns.rg/licenses/by-nc-sa/2.0/uk/legalcde

Exercises: Pltting Cmplex Figures in R 3 Exercise 1: Custmising simple plts The file weight_chart.txt cntains data fr a grwth chart fr a typical baby ver the first 9 mnths f its life. Read this file int a data frame using the read.delim functin. Use the plt functin t draw this as a pint and line graph (type= b ) with the fllwing changes. Apply each ne sequentially s yu can see the effect it has n the plt. Change the pint character t be a filled square (pch=15) Change the plt pint size t be 1.5x nrmal size (cex=1.5) Change the line thickness t be twice the default size (lwd=2) Change the y-axis t scale between 2 and 10kg (ylim=c(2,10)) Change the x-axis title t be Age (mnths) (xlab= Age (mnths) ) Change the y-axis title t be Weight (kg) (ylab= Weight (kg) ) Add a suitable title t the tp f the plt (main= Sme title ) The file feature_cunts.txt cntains a summary f the number f features f different types in the muse GRCm38 genme. Lad this int a data frame using read.delim and then plt it as a barplt. Nte that the data yu need t barplt is cntained within the Cunt clumn f the data frame, s yu pass nly that single clumn as the data fr the plt. Once yu have the basic plt make the fllwing changes: The bars shuld be hrizntal rather than vertical (hriz=true). The cunt axis shuld be labelled (xlab= A title ) The feature names shuld be added t the y axis. (set names.arg t the Feature clumn f the data frame) The plt shuld be given a suitable title (main= Sme title ) The text labels shuld all be hrizntal (las=1) Nte that yu can pass this parameter either via par, r as an additinal ptin t barplt. The margins shuld be adjusted t accmmdate the labels (par mar parameter). Yu need t supply a 4 element vectr fr the bttm,left,tp and right margin values. Lk at the value f par()$mar t see what the default values are s yu knw where t start. Nte that yu will have t redraw the barplt after making the changes with par. [Extensin if yu have time] Use this hist functin t plt ut the distributin f 10000 pints sampled frm a standard nrmal distributin (rnrm) alng with anther 10000 pints sampled frm the same distributin but with an ffset f 4. Example: c(rnrm(10000),rnrm(10000)+4) Find a suitable number f breaks t make the plt lk nicer (breaks=10 fr example)

Exercises: Pltting Cmplex Figures in R 4 Exercise 2: Using clur The file male_female_cunts.txt cntains a time series split int male and female cunt values. Plt this as a barplt Make all bars different clurs using the rainbw functin rainbw takes a single argument, which is the number f clurs t generate, eg rainbw(10) Try making the vectr f clurs separately befre passing it as the cl argument t barplt (cl=rainbw(10)). Rather than hard cding the number f clurs, think hw yu culd use nrw t autmatically generate the crrect number f clurs fr the size f dataset. Replt, and make the bars fr the males a different clur t thse fr the females. In this case the male and female samples alternate s yu can just pass a 2 clur vectr t the cl parameter t achieve this effect. (cl=c( blue2, red2 )) fr example. The file up_dwn_expressin.txt cntains an expressin cmparisn dataset, but has an extra clumn which classifies the rws int ne f 3 grups (up,dwn r unchanging). Plt this as a scatterplt (plt) with the up being red, the dwn being blue and the unchanging being grey. Read in the file using read.delim Start by just pltting the Cnditin1 clumn against the Cnditin2 clumn in a plt Pass the State clumn as the cl parameter (cl=up.dwn$state fr example). This will set the clur accrding t the state f each pint, but the clurs will be set autmatically frm the utput f palette Run palette() t see what clurs are there initially and check that yu can see hw these relate t the clurs yu get in yur plt. Run levels() n the State clumn data and match this with what yu saw in palette() t see hw each clur was selected. Wrk ut what clurs yu wuld need t put int palette t get the clur selectin yu actually want. Use the palette functin t set the crrespnding clurs yu want t use (eg palette(c( red, green, blue )) but using the crrect clurs in the crrect rder. Redraw the plt and check that the clurs are nw what yu wanted. The file clur_t_value_map.r cntains a functin t map a value frm a range t a clur frm a predefined palette. The file expressin_methylatin.txt cntains data fr gene bdy methylatin, prmter methylatin and gene expressin. Draw a scatterplt (plt) f the prmter.meth clumn against the gene.meth clumn. Nw yu can wrk n cluring this plt by the expressin clumn. Fr this yu are ging t need t run the map.clurs functin we prvided. This requires tw bits f

Exercises: Pltting Cmplex Figures in R 5 data ne is simply the values in the expressin clumn, but the ther is a vectr f clurs which define yur clur scale. Yu will need t start by cnstructing a clur palette functin frm grey t red. Run clrramppalette(c( grey, red )) t shw that yu can generate a functin which will make clurs running frm grey t red. Call the functin t generate a set f 100 clurs and save these int a suitably named variable ie: clrramppalette(c( grey, red ))(100). Nw generate yur actual clur vectr yu re ging t use. Call the map.clurs functin yu ve been given with the set f expressin clumn values, and the vectr f clurs yu just generated. Save the per pint clurs which are returned int a new variable. Finally redraw the plt passing the per pint clurs t the cl parameter.

Exercises: Pltting Cmplex Figures in R 6 Exercise 3: Using Overlays The file chrmsme_psitin_data.txt cntains psitinal cunt data fr 3 different datasets (a WT and tw mutants). Plt this as a line graph (using plt(type= l )) shwing the 3 different datasets verlaid. Yu ll need t d an initial plt with type= l specified fllwed by tw additinal layers using the lines functin. The x values will be the Psitin clumn in each case. The y values will be the WT clumn fr the initial plt, and then the Mut1 and Mut2 clumns fr the verlays. Remember t calculate the full range f values acrss all 3 datasets when ding the initial plt s that all f the data will fit int the plt area. Yu can pass the whle data prtin f the data frame (excluding the psitins) t range t d the calculatin ie: range(chr_psitins[,2:4]) Fr the clurs generate a 3 clur palette frm the Set1 RClrBrewer set using the brewer.pal(3, Set1 ) functin and save it. Pass a different clur frm the palette t each f the pltting functins yu call. Use the legend functin, t put a legend at the tpleft f the plt with the data names and the crrespnding clurs (using the fill parameter). Make the lines 2x as thick as standard (lwd=2) Add suitable labels t each axis (using xlab and ylab). The general structure fr yur cde will therefre be: plt( [psitin data], [wt data], ylim=[range data], type= l, cl=[first clur], lwd=2 ) lines([psitin data], [mut1 data], cl=[secnd clur], lwd=2) lines([psitin data], [mut2 data], cl=[third clur], lwd=2) legend( tpleft,c( wt, mut1, mut2 ),fill=[vectr f 3 clurs])

Exercises: Pltting Cmplex Figures in R 7 The file brain_bdyweight.txt cntains data fr the lg10 brain and bdyweight fr a range f species, alng with an SEM measure fr each pint. Plt these data n a scatterplt (using plt) with errr bars shwing the mean +/- SEM and the names f the datasets under each pint. Yu will initially need t d a plt passing the Bdyweight and Brainweight clumns as the data. Make sure this wrks befre trying t add errr bars. Yu will need t add 2 sets f errr bars, ne fr the Bdyweight and ne fr the Brainweight. These will be tw separate additinal layers, each cnsisting f an arrws functin. The arguments fr each arrws functin are: The x (brainweight) start psitin The y (bdyweight) start psitin The x (brainweight) end psitin The y (bdyweight) end psitin Additinal cmmn ptins will be angle=90 t prduce a flat head t the bars cde=3 t get a bar at bth ends f the line length=0.05 s the bars aren t t lng. The start and end psitins fr ne errr bar will be the riginal value plus and minus the crrespnding SEM. Fr example fr the brainweight cnfidence interval the cde wuld be smething like: arrws ( data$bdyweight, data$brainweight data$brainweight.sem, data$bdyweight, data$brainweight + data$brainweight.sem, angle=90, cde=3, length=0.05 ) Yu will, f curse, need t replace data with whatever yu actually called the data frame cntaining the data fr this exercise. Yu wuld als need t repeat this mdifying the Bdyweight values t get the Bdyweight errr bars. T add the names f the species just belw each data pint yu wuld use the text functin. The x and y values will just be the same as fr the riginal plt (Brainweight and Bdyweight). The labels will be the Species clumn. Other ptins yu will need t set will be: ps=1 t put the text underneath each pint cex=0.7 t make the text slightly smaller

Exercises: Pltting Cmplex Figures in R 8 Plt Results Belw are examples f what the plts yu will draw in these exercises shuld end up lking like. Exercise 1:

Exercise 2: Exercises: Pltting Cmplex Figures in R 9

Exercises: Pltting Cmplex Figures in R 10

Exercise 3: Exercises: Pltting Cmplex Figures in R 11