Professional Documents
Culture Documents
# bg – all subsequent plots will have a yellow • To generate a graphic in a new window, use
background the command:
- x11() in Linux
• There are 73 graphical parameters, some of them - windows() in Windows
have very similar functions.
• The exhaustive list of these parameters can be read
with ?par
• Some par elements can be modified from within high
and low level plotting functions
SUMMARY OF GRAPHICS AND
DATA FILE
• plot(x,y) or plot(y~x)
- x and y are the variables to be used for
SCATTERPLOT the x and y axes, respectively
- x and y are both numeric variables
> attach(gdata2)
> plot(Nitrogen, C463, main=“Plot
of Yield at Different Nitrogen
Rate”, xlab=“Nitrogen Rate",
ylab=“Grain Yield, col="Red")
# x – Nitrogen
# y – C463
• Use to create line charts that adds • Ex2. Adding line charts to plot()
information to a graph > lines(IR5~Nitrogen, pch=19,
col="blue", type="o", lty=1)
> lines(x,y, type= …)
> lines(IR8~Nitrogen, pch=19,
> lines(y~x, type= …) col=“green", type="o", lty=1)
> lines(Peta~Nitrogen, pch=19,
# x and y – numeric vectors of points to connect
col=“brown", type="o", lty=1)
DATAFRAME : gdata3.csv
barplot()
barplot(height, # vector or matrix of values describing
• Summary of Variety Means
# the bars which make up the plot.
beside = FALSE, # stacked by default. If
# TRUE bars will be side
# by side
density = NULL, # a vector giving the density of
# shading lines, in lines per inch,
# for the bars or bar components.
# The default value of NULL
# means that no shading lines are
# drawn.
xlab = NULL, # label for x-axis
ylab = NULL, # label for y-axis
ylim = NULL) # limit for y-axis
DATA FRAME: gdata3 SIMPLE BAR PLOT : gdata3
Read data file gdata3.csv
gdata3.csv > barplot(gdata3$Yield)
> gdata3 <- read.table(“
read.table(“gdata3.csv",
gdata3.csv",
header=T, sep=",")
> gdata3
Variety Yield
1 V1 4.7559
2 V2 5.0410
3 V3 5.0581
PACKAGE ‘sciplot’
• A collection of functions that creates
graphs with error bars for data collected
from one-way or higher factorial designs.
ERROR BARS
• It has three available functions:
> bargraph.CI()
> lineplot.CI()
> se()
BARGRAPH WITH ERROR BARS: BARGRAPH WITH ERROR BARS:
bargraph.CI() bargraph.CI()
• Use to obtain barplot of the mean and standard
error of a response variable.
• Usage:
• Usage: > bargraph.CI(x.factor, response,
group, density, angle, legend,
> bargraph.CI(x.factor, response, x.leg, cex.leg …)
group, …)
# x.leg, y.leg – to over ride the default legend
# x.factor – a factor whose levels will form the placement
x-axis
# cex.leg – character expansion value for
# response – numeric response variable legend values
# group – grouping factor whose levels will
form groups of bars for each level of x.factor
GRAPHICAL DEVICES
GRAPHICAL DEVICE USAGE OF GRAPHICS DEVICE
• Before you create your graphs, you can decide
on a format for output. The format is called a jpeg(filename=“
jpeg(filename=“plot.jpg”
plot.jpg”, width=480,
device. height=480, pointsize=12,
• A graphical device is a graphical window or a units=“
units=“px”
px”)
file.
file.
png() – same parameters as jpeg
• Some commonly used graphical device
pdf() Produces PDF file pdf(file=“
pdf(file=“plot.pdf”
plot.pdf”, width=7,
height=7, paper = “a4”
a4”)
png() Produces a bitmap PNG file
jpeg() Produces a bitmap JPEG file # filename - the name of the output file
>
>
png(filename=“
png(filename=“hist.png”
hist(gdata$Y)
hist.png”) THANK YOU! ☺
> dev.off() Please do Exercise C