library(ggplot2);library(gcookbook)data = read.csv("datafile.csv",header=TRUE)data = read.csv("datafile.csv", header=FALSE)names(data) = c("Column1","Column2","Column3")data = read.csv("datafile.csv", sep="\t")data = read.csv("datafile.csv", stringsAsFactors=FALSE)data$Sex = factor(data$Sex)install.packages("gdata")
library(gdata)
data = read.xlsx("datafile.xlsx", sheetIndex=2)data = read.xlsx("datafile.xls", sheetName="Revenues")data = read.xls("datafile.xls", sheet=2)install.packages("foreign")
library(foreign)
data = read.spss("datafile.sav")
data = read.dta("datafile.dta")
plot(mtcars$wt, mtcars$mpg)
library(ggplot2)
qplot(mtcars$wt, mtcars$mpg) #qplot(wt, mpg, data=mtcars)
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()
plot(pressure$temperature, pressure$pressure, type="l")
plot(pressure$temperature, pressure$pressure, type="l")
points(pressure$temperature, pressure$pressure)
plot(pressure$temperature, pressure$pressure, type="l")
lines(pressure$temperature, pressure$pressure/2, col="red")
points(pressure$temperature, pressure$pressure/2, col="red")
ggplot(pressure, aes(x=temperature, y=pressure)) + geom_line()
ggplot(pressure, aes(x=temperature, y=pressure)) + geom_line() + geom_point()
barplot(BOD$demand, names.arg=BOD$Time)
table(mtcars$cyl)
4 6 8
11 7 14
# Generate a table of counts
barplot(table(mtcars$cyl))
library(ggplot2)
qplot(BOD$Time, BOD$demand, geom="bar", stat="identity")
# Convert the x variable to a factor, so that it is treated as discrete
qplot(factor(BOD$Time), BOD$demand, geom="bar", stat="identity")
# cyl is continuous here
qplot(mtcars$cyl)
# Treat cyl as discrete
qplot(factor(mtcars$cyl))
ggplot(BOD, aes(x=Time, y=demand)) + geom_bar(stat="identity")
# Bar graph of counts
ggplot(mtcars, aes(x=factor(cyl))) + geom_bar()
hist(mtcars$mpg)
# Specify approximate number of bins with breaks
hist(mtcars$mpg, breaks=10)
library(ggplot2)
ggplot(mtcars, aes(x=mpg)) + geom_histogram(binwidth=4)
plot(ToothGrowth$supp, ToothGrowth$len)
# Formula syntax
boxplot(len ~ supp, data = ToothGrowth)
# Put interaction of two variables on x-axis
boxplot(len ~ supp + dose, data = ToothGrowth)
ggplot(ToothGrowth, aes(x=supp, y=len)) + geom_boxplot()
ggplot(ToothGrowth, aes(x=interaction(supp, dose), y=len)) + geom_boxplot()
curve(x^3 - 5*x, from=-4, to=4)