Tutorial

tutorial

View project on GitHub

Types of graphs

There are five types of graph and four types of ggplot2 graph right now. More types will be updated.

Plot Type Function name in RIGHT Function name in ggplot
Scatter plot
  plot(---, ---, type="p"))
  (---, aes(---)) + geom_point()
Bar plot
  hist(---, ---)
  (---, aes(---)) + geom_bar()
Box and Whisker plot
  boxplot(---, ---)
  (---, aes(---)) + geom_boxplot()
Line plot
  plot(---, ---, type= "l")
  (---, aes(---)) + geom_line()
Pie plot
  pie(---, ---)
  no support in ggplot2

Here is a summary of what types of interactivity each plot supports: LET'S SUMMARIZE WHAT TYPES OF INTERACTIVITY EACH PLOT TYPE SUPPORTS IN A TABLE. Read more about types of supported interactivity and supported plotting options.

1. Scatter plot

RIGHT(plot(form, data, type="p", col)) RIGHT(print(ggplot(data, aes(form, colour)) + geom_point()))

  • Scatter plot, display values for two variables for a set of data.
  • Regression (linear, loess) is enabled. The calculation for a regression line is done by the server side with R. (Shiny library is used here) To draw basic scatter graph type:
> subDiamonds <- diamonds[sample(1:nrow(diamonds), 50, T) ,]
> RIGHT(plot(price ~ carat, subDiamonds, type="p", col=color))

or you can make same graph using ggplot2 or qplot API

> RIGHT(print(ggplot(subDiamonds, aes(carat, price, colour=color)) + geom_point()))

If you want to use qplot function,

> RIGHT(qplot(x=carat, y=price, data=subDiamonds, geom="point", colour=color))

2. Bar plot

RIGHT(hist(form, data, col)) RIGHT(print(ggplot(data, aes(form, fill)) + geom_bar()))

  • Bar plot, rectangular bars with lengths proportional to the values. To draw basic bar graph type:
> RIGHT(hist(price, subDiamonds, col=color))

or

> RIGHT(print(ggplot(subDiamonds, aes(price, fill = color)) + geom_bar()))

If you want to use qplot function,

> RIGHT(qplot(x=price, fill=color, data=subDiamonds, geom="bar"))

3. Box and Whisker plot

RIGHT(boxplot(form, data)) RIGHT(print(ggplot(data, aes(form)) + geom_boxplot()))

  • Box and Whisker plot, a convenient way of graphically depicting groups of numerical data through their quartiles. To draw basic box and whisker graph type:
> subArray <- diamonds[sample(1:nrow(diamonds), 1000, TRUE), ]
> RIGHT(boxplot(price ~ color, subArray))

or

> RIGHT(print(ggplot(subArray, aes(color, price)) + geom_boxplot()))

If you want to use qplot function,

> RIGHT(qplot(x=color, y=price, data=subArray, geom="boxplot"))

4. Line plot

RIGHT(plot(form, data, type= "l")) RIGHT(print(ggplot(data, aes(form)) + geom_line()))

  • Line plot, displays information as a series of data points connected by straight line segments. To draw basic line graph type:
> RIGHT(plot(price ~ carat, subDiamonds, type= "l"))

or

> RIGHT(print(ggplot(subDiamonds, aes(carat, price)) + geom_line()))

If you want to use qplot function,

> RIGHT(qplot(x=carat, y=price, data=subDiamonds, geom="line"))

5. Pie chart

RIGHT(pie(form, data)) no support in ggplot2

  • Pie chart, circular chart divided into sectors, illustrating numerical proportion. To draw basic pie graph type:
> RIGHT(pie(color, subDiamonds))

There is no support using ggplot2 API to draw pie chart