R Programming Articles

Page 39 of 174

How to create boxplot for a list object in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

A list object can contain multiple elements of data, also the size of the data may vary. If a list object has numerical vectors then the boxplot for each of the elements can be created simply by using boxplot function. For example, if we have a list object called LIST that contains five numerical vectors then the boxplot for each of the vectors can be created by using the command boxplot(LIST)ExampleList

Read More

How to change the default type of points for scatterplot using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 301 Views

To change the defaults for ggplot2 geoms, we need to use update_geom_defaults function. If we want to change the shape of points for scatterplot, we can use the below syntax −update_geom_defaults("point",list(shape=”point_shape_number”))The point shape number ranges from 0 to 25. We can change that according to our need.Consider the below data frame −Examplex

Read More

How to create boxplot for list elements using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 753 Views

If list elements are of equal size having numerical values then the boxplot for each element can be created by using ggplot2 but before creating the boxplot we would need to convert the list to a data frame. The conversion of list elements to a data frame will be done by unlisting of elements and creating two columns, one for categories and one for response variable. Check out the below example to understand how it works.Consider the below list −ExampleList

Read More

How to extract axes labels for the plot drawn using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 634 Views

When we create a plot using ggplot2, the axes labels are automatically generated for both the axes. We might want to use those axes labels for report writing or some other purpose, therefore, extraction of those labels for a plot created by using ggplot2 package can be found by using the ggplot_build function as shown in the below example but we need to save the plot in an object.Consider the below data frame −Examplex

Read More

How to multiply only one column in an R data frame with a number?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

To multiply only one column with a number, we can simply use the multiplication operator * but need to replace the original column with the new values. For example, if we have a data frame called df that contains three columns x1, x2, and x3, and we want to multiply the second column x2 with 2 then it can be done as df$x2

Read More

How to create a combination of pairs from a vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

To create a combination of pairs, we can use the combn function. This function will be helpful to use the vector length and the value 2 that represents a pair to create the combinations. Although, this is enough but we can transpose the output to get a better−looking output.Example1x1

Read More

How to increase the X-axis length of histogram in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 6K+ Views

To increase the X-axis length of histogram in base R, we can use the axis function. The most important thing to remember while using the axis function is mentioning the appropriate sequence based on the values in the vector or in the column of the data frame if a data frame is used.Examplex

Read More

How to set the plot area to assign the plots manually in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 128 Views

We can split the screen to assign the plots manually in the plot area. The split.screen function can be used for this purpose. For example, if we want to create 4 plots in the plot window then we can use split.screen(c(2, 2)). Now to create the plot in first screen the command will be screen(1) then plot will be created. If we again create the plot then the original plot in screen(1) will be replaced with the new one. To create the plot in 3rd screen that is screen(3), we first need to use the command screen(3) and then create ...

Read More

How to create a single data frame from data frames stored in a list with row names in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 218 Views

If we have multiples data frames of same size stored in a list and we believe that these data frames have similar characteristic then we can create a single data frame. This can be done with the help of do.call. For example, if we have a list defined with the name List containing data frames with equal number of rows with their names then a single data frame can be created do.call(rbind,unname(List)).Exampledf1

Read More

How to convert columns of an R data frame into a single vector?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

Sometimes all the columns in a data frame have similar data characteristics representing a particular variable. For example, having a data frame containing five columns each with heights of people. To convert this type of data frame into a vector we can use as.vector function along with the as.matrix function. The as.matrix will read the data frame columns so that the array of values can be created.Example1y1

Read More
Showing 381–390 of 1,740 articles
« Prev 1 37 38 39 40 41 174 Next »
Advertisements