Page 265 - Data Science class 11
P. 265

7.7.1 histogram of Weight Variable V

            Specifying the Range of X and Y values
            The xlim and ylim parameters can be used to specify the range of values allowed on the X and Y axes.
            The width of each bar can be decided by using breaks.

            The below script will create and save a line chart in the current R working directory.

                # Creating data for the graph.
                v <- c(9,13,21,8,36,22,12,41,31,33,19)
                # Giving the chart file a name.
                png(file = "histogram_lim_breaks.png")
                # Creating the histogram.
                hist(v,xlab = "Weight",col = "green",border = "red", xlim = c(0,40), ylim = c(0,5),
                   breaks = 5)
                # Saving the file.
                dev.off()
            When we execute the above code, it produces the following result:






























                                                     Histogram Line Breaks

            Analyse the histogram to see whether it represents a normal distribution. Once you have plotted all the frequencies
            on the histogram, your histogram will show a shape. If the shape looks like a bell curve, it would mean that the
            frequencies are equally distributed. The histogram would have a peak.


            7.8 scatterplots

            Scatter plots are dispersion graphs built to represent the data points of variables (generally two, but can also be
            three). The main use of a scatter plot in R is to visually check if there is some relation between numeric variables.
            Scatterplots show many points plotted in the Cartesian plane. Each point represents the values of two variables. One
            variable is chosen in the horizontal axis and another in the vertical axis.
            A scatter plot is a set of dotted points to represent individual pieces of data on the horizontal and vertical axis. A
            graph in which the values of two variables are plotted along the X-axis and Y-axis, the pattern of the resulting points
            reveals a correlation between them.


                                                           Coding for Data Science Visualisation using R-Studio  263
   260   261   262   263   264   265   266   267   268   269   270