Professional Documents
Culture Documents
Data files have many formats and accordingly we have options for loading them.
>data=read.csv(“C:\\Users\\admin\\Desktop\\data.csv”) Or
>data=read.csv(“C:/Users/admin/Desktop/stud .csv”)
Find the number of observations in Animals using the structure command. Note this also
gives you information about the class of the object and the types of variables
>str(Animals)
Output:
You may also want to explore the relationships between variables in your data. For
example, you could investigate the correlation between body and brain weight in
Animals.
cor(Animals$brain, Animals$body)
Output:
[1] -0.005341163
For a more detailed look at what values of our data seem to go together, you could also
use cross tabulation. There are several ways to do this in R. Use the Uscereal data in R to
practice cross tabulation.
A simple plot plot(X) has each element of a discrete variable X ploted on the y-
axis and the element's index on the x-axis.
Pie Charts
Pie charts are commonly used to visualize the proportion of data belonging to
certain categories. While common in news media, pie charts are controversial
among data visualizers, statisticians, and data scientists. Essentially, experts argue,
humans have a very difficult time visually assessing the differences among
categories using a single pie chart (because it requires evaluating area rather than
length, as in a bar chart), and that comparing across pie charts is nearly impossible.
Great alternatives to a pie chart include bar charts and dot plots.
Box Plots
Box/whisker plots summarize the distribution of data in a collapsed format, often
representing the mean of the data in each of several categories, the quantiles, and
any outliers. Violin plots are a variation on boxplots utilizing kernel density to
illustrate the density of the data distribution rather than a collapsed summary.
Editing Base Graphics
You may have noticed that R includes a significant amount of information in
plots by default, often including axis labels and titles or colors, but that whether
and what is included varies. To edit these characteristics of plots yourself, you will
commonly use the plot() command.
More Advanced Base Graphics
In addition to having built-in data, R also has a built-in demo for some of its more
advanced graphics options. You can walk through these demos as follows: