Reputation: 2544
I am going through some teaching materials of the R function 'plot', and I already have tons of questions. To begin with, I would like to understand how the 'type' parameter works and when it works.
My code:
t<-seq(from=0, to=10, by=0.1)
y<-sin(t)
#changing the type parameter here works, I can see the difference
#between, e.g., line or histogram
plot(x=t, y=y,
type="h",
xlab="Angle",
ylab="Sine",
col="red",
main="Sine function")
rio <- read.csv(".../Rio2016.csv")
#see screenshot below for what the data look like
View(rio)
countries <- rio$Country
gold <- rio$Gold
silver <- rio$Silver
bronze <- rio$Bronze
# changing the type param here does not work. No matter
# what I tried, it always display the same thing
plot(x=countries,y=silver, type="h",
xlab="Countries",
ylab="Gold",
col="red",
main="Gold Medals")
In the first plot, when I tried to change the type parameter, I get the graphics changed accordingly. Like this
However, when I try to do the same for another real dataset (see below), it does not work. Dataset looks like this:
No matter what 'type' I tried, it always displays like this:
How does the 'type' parameter work? Thanks
Upvotes: 1
Views: 841
Reputation: 859
The reason you are seeing the same kind of plot regardless of the 'type' parameter is due to the fact that the 'Country' column of your dataset is of type 'factor'.
Try taking another column as 'x' or define x=as.numeric(countries)
you will see that some 'type' values are then not allowed while type="p"
will display a plot with points.
Upvotes: 1