1 / 26

Easy plotting with R

A reference guide with examples for plotting in R. Introduction to R and Rstudio. Basic R abilities, packages, paths, data. Learn about the power and flexibility of R. Make beautiful plots effortlessly.

augustinel
Download Presentation

Easy plotting with R

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Easy plotting with R Yoo! R so beautiful Talia Kustin reference

  2. Examples reference

  3. Agenda • Introduction to R and Rstudio • Basic R abilities • Packages, paths, data • Plotting in R: • Introduction • First plot together • Second plot – on your own!

  4. What is R? • Open source programming language • Great for statistical computing, graphics and data analysis

  5. Why use R? • R is free • R is popular • R is powerful • R is flexible • R is supported

  6. How does R work? • Functions: • Print • Plot graph • Open file • Variables: • Data and tables • Text • Numbers my_name<- “Talia Kustin” Function- print(my_name) Result - “Talia Kustin”

  7. Keyboard shortcuts • Control + enter  run current line / selection in console • Alt + -  Insert assignment operator (<-) • Control + 1  Move to script editor • Control + 2  Move to console More shortcuts here

  8. Script viewer • Write scripts and save them as files • Run lines in the console (Control + enter)

  9. Data viewer • View data • Filter data

  10. Console • Write command and run them • Run commands from the script viewer (Control + enter) • Saves history of commands run (up and down with the arrow keys) • Working path

  11. Upper panel • Environment • Data – all the tables that are used in this session • Values – strings, numbers and more • History – all commands typed

  12. Lower panel • Files – list of all files in the working directory • Plots – all the plots that we drew • Packages – all packages installed • (see specific slide) • Help – see next slide

  13. Where can I get help? • R studio help • Ask the professionals

  14. Useful packages in R • ggplot2 – plotting • ggsignif– statistical test for plots • plyr–summaries data and more • reshape2 - restructure and aggregate data

  15. Packages in R • There are lot’s of packages in R • Install • Load

  16. Installing packages in R • ggplot2 • ggsignif • plyr • reshape

  17. Paths • Every directory and file has a path • Desktop - c:/Users/(username)/Desktop • File in desktop - c:/Users/(username)/Desktop/file.docx • When we work with files and directories we have to specify it to the program

  18. Set directory • Specify a working directory: • setwd(“c:/Users/(username)/Desktop”) • Get the working directory: • getwd()

  19. Data files • CSV = comma-separated values • R can work with excel files as well =

  20. Data import • experiment<- read.csv(“c:/Users/(username)/Desktop/experiment.csv”) Or • setwd(“c:/Users/(username)/Desktop”) • experiment<- read.csv(”experiment.csv”) Or • file <- file.choose() #chose file from file explorer • experiment<- read.csv(file)

  21. Data in R • Get information on data: • class(experiment ) • str(experiment ) • colnames(experiment ) • dim(experiment ) • experiment reference

  22. Wide vs long formats • Usually we use wide format • For plotting in R we need long format melt dcast

  23. experiment: Melt command(wide  long) experiment_long <- melt(experiment, id.vars=c("subject", "sex"), variable.name="condition", value.name="measurement" ) הפקודה משתנים קטגוריאליים ה-data.frame הישן ה-data.frame החדש שם המשתנה החדש שם הערך

  24. Wide vs long formats experiment_long experiment

  25. experiment_long: Data in R • Get information on data #2 • max(experiment_long$measurement) – 13.8 • min(experiment_long$measurement) – 1.3 • mean(experiment_long$measurement) - 9.116667 • unique(experiment_long$condition) – control cond1 cond2 • length(experiment_long$sex[which(experiment_long$sex=="Female")]) - 6

More Related