Found 2038 Articles for R Programming

How to create multiple lines chart with unique line types in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:43:19

128 Views

Line types can be very different and they are helpful to differentiate among different variables. Mostly, it is used to plot trend data so that the trend for different variables can be visualized with a unique line. In R, we can use matplot function to create such type of multiple lines chart.Example1 Live DemoM1

How to create polynomial regression model in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:41:05

856 Views

A Polynomial regression model is the type of model in which the dependent variable does not have linear relationship with the independent variables rather they have nth degree relationship. For example, a dependent variable x can depend on an independent variable y-square. There are two ways to create a polynomial regression in R, first one is using polym function and second one is using I() function.Example1set.seed(322) x1

How to create relative frequency table using dplyr in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:39:45

529 Views

The relative frequency is the proportion of something out of total. For example, if we have 5 bananas, 6 guava, 10 pomegranates then the relative frequency of banana would be 5 divided by the total sum of 5, 6, and 10 that is 21 hence it can be also called proportional frequency.Example1 Live DemoConsider the below data frame −set.seed(21) x%mutate(freq=n/sum(n)) `summarise()` ungrouping output (override with `.groups` argument) # A tibble: 4 x 3Outputx n freq 1 A 3 0.15 2 B 7 0.35 3 C 7 0.35 4 D 3 0.15 Warning message: `...` is not empty. We ... Read More

How to create stacked barplot using barplot function with each bar having unique color in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:38:35

307 Views

In a bar plot, each bar represents one category of a single categorical variable but in a stacked bar plot, the bars represent same categorical variable but each divided into sub-categories. If we want to have similar distribution of colors in each bar then col argument with barplot function can be used.Example1 Live DemoM1

How to remove continuously repeated duplicates in an R data frame column?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:35:37

140 Views

Often values are repeated that generate duplication in the data and we might want to get rid of those values if they are not likely to create bias in the output of the analysis. For example, if we have a column that defines a process and we take the output of the process five times but it takes the same output all the time then we might want to use only one output.Example1 Live DemoConsider the below data frame −ID

How to extract the model equation from model object in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:33:15

2K+ Views

To extract the model equation model object, we can use the model object name with dollar sign and call function. For example, if we have a model object name Model then the model equation can be extracted by using Model$call. This will directly present the equation that was used to create the model.Example1 Live Demox1

How to set the chart title at the bottom using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:31:50

1K+ Views

Generally, the chart title is written on the upper side of the plot but sometimes we need to put it in the bottom. This is recommended in situations when the chart title explains something about the plot. For example, if we are plotting a normal distribution then we can use “Approximately Normal” as the chart title in the bottom because we know that perfect normal is a very rare event. If we want to set the chart title at the bottom in a chart created by using ggplot2 then we need to use grid.arrange function of gridExtra package.ExampleConsider the below ... Read More

How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:29:58

3K+ Views

The border thickness highlights the bars and this could be useful in situations where we have similar frequencies. If we want to change the thickness of the bars then size argument under geom_bar function of ggplot2 package can be used and it can be set according to our need starting from 1.ExampleConsider the below data frame −x

How to create stacked barplot using barplot function in R?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:28:12

331 Views

To create a stacked barplot using barplot function we need to use matrix instead of a data frame object because in R barplot function can be used for a vector or for a matrix only. We must be very careful if we want to create a stacked bar plot using barplot function because bar plots are created for count data only. Here, you will see some examples of count as well as continuous data, carefully read the graphs and understand how the graphs are different from each other.Example1 Live DemoM1

How to remove rows that contains all zeros in an R data frame?

Nizamuddin Siddiqui
Updated on 07-Nov-2020 11:23:54

8K+ Views

Often, we get missing data and sometimes missing data is filled with zeros if zero is not the actual range for a variable. In this type of situations, we can remove the rows where all the values are zero. For this purpose, we can use rowSums function and if the sum is greater than zero then keep the row otherwise neglect it.Example1 Live DemoConsider the below data frame −set.seed(251) x1

Advertisements