How to make multiple smoothing lines in ggvis?
In this article, we are going to see How to make multiple smoothing lines in ggvis using R Programming Language.
Make multiple smoothing lines in ggvis
The ggvis package in R is used for data visualization. It is also used to create interactive web graphics. It is also used to create interactive graphs and plots. It is an addition to the ggplot package. It provides the framework to build HTML graphs in the working space. The package can be downloaded and installed into the working space using the following command :
A data frame can be created using the data.frame method which takes as input a number of columns and the values stored in it. This data can be visualized using the ggvis method which computes the visual representation of the y-axis and x-axis data contained in the data frame. The ggvis method has the following syntax.
- ~y,~x- y-axis and x-axis of the data frame
- stroke- the different color values to plot different lines in ggvis
This is followed by the application of layers_lines() method using the pipe operator. The line segments are plotted connecting the y and x axis respectively. The points can also be marked significantly representing the data values contained within the data frame. This method is used to also sort the data that is available on the x variable. All the lines are plotted from left to right direction.
This is followed by the application of layer_points() method which is used to mark the data points on the plotted graph. This method as the following syntax.
- size- the size of the data points to be plotted.
- fill- the color of the data points to be plotted.
The following code shows two groups that are to be plotted in terms of the ratings given by the people. One line is drawn for the group GeeksForGeeks and another for Geekster using different colors.
 "Original Data frame" > print(data_frame) group people rating 1 Geekster 10 4 2 GeeksforGeeks 12 3 3 Geekster 21 5 4 Geekster 45 7 5 GeeksforGeeks 23 2 6 GeeksforGeeks 54 8 7 Geekster 22 1 8 GeeksforGeeks 12 10 9 Geekster 32 9 10 Geekster 45 6
The following code snippet shows four groups instead of two that are used for plotting thereby the plot contains four different color lines.
 "Original Data frame" > print(data_frame) group people rating 1 Geekster 10 4 2 TCS 12 3 3 Geekster 21 5 4 Geekster 45 7 5 GeeksforGeeks 23 2 6 Wipro 54 8 7 Geekster 22 1 8 GeeksforGeeks 12 10 9 Geekster 32 9 10 Wipro 45 6 11 TCS 65 5