Level up your Data Visualizations with quick plot
Data Visualization is an essential part of a Data Scientists workflow. It allows us to visually understand our problem, analyses our models, and allows us to provide deep meaningful understanding to communities.
As Data Scientists, we always look new ways of improving our data science workflow.
Why should I use this over ggplot? Is their any differences? What are the benefits?
Qplot allows sharper, shorter and more concise syntax for declaring ggplot visualizations. It is a great swiss army knife for plotting quick easy visualizations and is easily readable for those who haven’t used ggplot or R before.
qplot stands simply for quick plot
is a shortcut designed to be familiar to ggplot2.
Let’s see how it works!
Below I’ll show two ways of plotting the same visualization. Using ggplot2 first, then using qplot.
ggplot2
ggplot(mpg) +
geom_point(aes(displ, hwy, color = factor(cyl), shape = factor(cyl)))
qplot
qplot(displ, hwy, data = mpg, colour = factor(cyl), shape = factor(cyl))
By using quick plot, we can shorten the syntax and make it more clear and concise. The syntax becomes very similar to the seaborn
library if you have programmed in python before.
Let’s take a look at a couple more examples!
Bar Chart
ggplot2
ggplot(data = diamonds) +
geom_bar(aes(color, weight = carat, fill = color, alpha = 0.5)) + scale_y_continuous("carat")
qplot
qplot(color, data = diamonds, geom = "bar", weight = carat, fill = color, alpha = 0.5) + scale_y_continuous("carat")
Scatter-plot & Line Chart
First we’ll take a small sample from the diamonds data set.
dsmall <- diamonds[sample(nrow(diamonds), 100),]
ggplot
ggplot(dsmall, aes(carat, price)) + geom_point() + geom_smooth()
qplot
qplot(carat, price, data = dsmall, geom = c("point", "smooth"))
Boxplot
ggplot
ggplot(data = mpg) +
geom_boxplot(mapping = aes(x = drv, y = hwy, color = manufacturer))
qplot
qplot(drv, hwy, data = mpg, color = manufacturer, geom = 'boxplot' )
Fin
I hope this story taught you something new! Both ggplot and qplot can be used to achieve the same effect. But if you ever want decide to be indie, have a try of qplot for quick, dirty and simple data visualizations for Exploratory Data Analysis!
As always, I welcome feedback and constructive criticism. I can be reached on Twitter @Chippasaur.