0% found this document useful (0 votes)
47 views

R Notes

The document discusses various data visualization techniques in R including line charts, bar charts, histograms, pie charts, dot charts, scatter plots, and boxplots. It provides examples of how to load, handle, and plot different types of data from files or vectors. Key steps mentioned include reading data from files using read.csv(), binding data with cbind(), sorting with order(), and plotting relationships between variables.

Uploaded by

Shivam Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

R Notes

The document discusses various data visualization techniques in R including line charts, bar charts, histograms, pie charts, dot charts, scatter plots, and boxplots. It provides examples of how to load, handle, and plot different types of data from files or vectors. Key steps mentioned include reading data from files using read.csv(), binding data with cbind(), sorting with order(), and plotting relationships between variables.

Uploaded by

Shivam Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Cars

1
3
6
4
9

Trucks
2
5
4
5
12

Suvs
4
4
6
6
16

Line charts:
Define the cars vector with 5 values:

Cars <- c(1,3,6,4,9)


Plot(cars)

For 2 graphs:
Cars <- c(1,3,6,3,9)
Trucks <- c(2,5,4,5,12)
Plot(cars)
Lines (trucks)
Bar charts:
Cars <- c(1,3,6,4,9)
Barplot(cars)
Another way:
Autos_data <- read.table(c:/R/autos.dat, header=T,sep=\t)
Barplot(autos_data$cars, main=cars, xlab= Days, ylab=total,
Names.arg=c(Mon,tue,wed,thurs,fri),
Border=blue, density=c(10,20,30,40,50))
Another way:
Autos_data <- read.table(c:/R/autos.dat, header=T,sep=\t)
Barplot(as.matrix(autos_data), main=autos,ylab=total,beside=TRUE, col=rainbow(5))

Histograms:
Cars <- c(4,4,6,616)
Hist(suvs)
If u wanna get a random log-normal distribution:
R <- rlnorm(1000)
Hist( r )
If we want to show some distribution with axes:
R <- rlnorm(1000)
H <- hist(r, plot=F, breaks=c(seq(0,max(r )+1,.1)))
Plot(h$counts, log=xy, pch=20, col=blue, main=log-normal,
Xlab=Value, yab=frequency)

Pie charts:
Cars <- c(1,3,6,4,9)
Pie(cars)

Dot charts:
Autos_data <- read.table(c:/R/autos.dat, header=T,sep=\t)
Dotchart(t(autos_data))

Scatter plots:
Attach(cars)
Plot(wt,mpg, main=scatterplot

Boxplot(education$high)

Loading and handling data:

C(1,2,3,4,5)
To assign to variable:
Fakedata <- c(1,2,3,4,5)
Fakedata[1] tells u accessing the data.
Fake1 <- c(a, a, a, a, a)
Cbind(fakedata, fake1)

How to load a CSV file:

Edu <- read.csv(filename.csv, header=TRUE, sep=,, as.is=TRUE)

Sorting the data we use the order() function


High.order <- order(filename$high)
High.order <- order(filename$high, decreasing=TRUE)
To view the data
Edit -> data editor -> file name
Summary of the data
Summary (filename)
To plot the data and check between variables we need to verify
Plot (file_name$column_name, file_name$column_name)
To choose a file from the r-command
Read.csv (file.choose(),header=T) -> another_file_name
Str(another_file_name)
This is for the virtual data created here to access and work on.
To find range for a particular column
Range (filename [,column_name])
Library(RODBC)

To install any packages then:


Install.packages (package_name)
Histogram:
Hist (filename $ column_name) presents the data with frequency how it is varying

You might also like