wdcplot(mtcars,
dimensions(..index.., mpg, wt, cyl),
groups(mpgGroup = group(mpg, bin(2)),
wtGroup = group(wt, group = bin(0.5)),
cylinders = group(cyl)),
charts(SWvL = bubble('Miles Per Gallon vs. Weight',
dimension = ..index..,
color = cyl,
x = wt,
y = mpg,
r = ..selected.. * 3,
label = NULL),
cyl = pie("Cylinders",group = cylinders),
PW = bar('Miles Per Gallon', group = mpgGroup, x.domain = c(10.4,33.9)),
PL = bar('Weight', group = wtGroup, x.domain = c(1.5,5.5))
))
-
-
Save s-u/2f638b6b141fc490a703 to your computer and use it in GitHub Desktop.
wDCPlot with mtcars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We don't want a numeric vector. We want a data.frame slice. | |
head(mtcars["mpg"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Did we do it right? What's the type/class? | |
class(mtcars["mpg"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How do I get more than one column? | |
head(mtcars[c("mpg","hp")]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How do we know the row names? | |
row.names(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How do we access a specific value? | |
mtcars["Mazda RX4", "cyl"] | |
# OR | |
mtcars[1,2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How do I access a row? | |
mtcars["Mazda RX4", ] | |
# Also the same as ... | |
mtcars[1, ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Vehicles with automatic transmission? | |
head(mtcars[mtcars$am==0,]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mileage for automatic transmission vehicles | |
mtcars[mtcars$am==0,]$mpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's know our data better | |
summary(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We don't want to keep typing mtcars$... so we use attach | |
attach(mtcars) | |
# You can now directly refer mtcars$mpg as mpg | |
identical(mtcars$mpg, mpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's load the popular mtcars dataset. It comes pre-bundled with R | |
data(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's summarize our data | |
table(cyl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plotting is easy | |
barplot(table(cyl)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OR a histogram | |
hist(mpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OR a boxplot | |
boxplot(mpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Looks like mpg are pretty low | |
mean(mpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mean of mileage for 4 cylinder cars | |
mean(mpg[cyl==4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vs 8 cylinder cars | |
mean(mpg[cyl==8]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Is that because of a higher number of cylinders? | |
plot(cyl, mpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's fit a regression line | |
lm(mpg~cyl+hp) | |
# Pearson correlation, is that a good fit? | |
cor(mpg,cyl)^2 | |
cor(mpg, hp)^2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's plot based on number of cylinders | |
plot(hp,mpg,pch=19, col=cyl) | |
# add a legend | |
legend(250, 30, pch=19, col=c(4,6,8), legend=c("4 cylinders","6 cylinders","8 cylinders")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Now we do the cool stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detach(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What does the data look like? | |
head(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Looks like mtcars is a data frame | |
class(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So the structure is ... | |
str(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What are the total number of rows? | |
nrow(mtcars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How do we access a column? | |
head(mtcars$mpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What's the type/class? | |
class(mtcars$mpg) | |
# OR | |
head(mtcars[,1]) | |
# OR | |
head(mtcars[, "mpg"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# scratch file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment