Found 2038 Articles for R Programming

How to change the color of X-axis label using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 09:05:04

6K+ Views

The default color of labels is black but we might want to change that color to something else so that we can get attention of the viewer to the labels if it is needed. To change the color of X-axis label using ggplot2, we can use theme function that has axis.title.x argument which can be used for changing the color of the label values.ExampleConsider the below data frame − Live Demox

How to extract column names that do not have even one missing value in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:59:48

309 Views

The extraction of column names that do not have missing values can be done with the help of colnames function along with the complete.cases function. The complete.cases function will extract the columns that do not have missing values then colnames will extract those column names only.Example1Consider the below data frame − Live Demox1

How to convert dot to comma for numerical columns in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:55:26

2K+ Views

Most European countries use a comma in place of a decimal. Therefore, if we have a data set that contains dot as a decimal market and we need to use that four such European countries or if dot is recorded in place of comma then we can replace the dot with comma using format function as shown in the below examples.Example1 Live DemoConsider the below data frame −x1

How to change the background color of legend in base R plot?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:52:12

2K+ Views

To create the legend for a plot in base R, we can use legend function and if the background color of the legends needs to be changed from white to any other then bg argument in legend function will be used. For example, to change the background color to red then we can use bg="red".Example1 Live Demoplot(1:10) legend("right",legend="point chart",bg="blue")OutputExample2 Live Demoplot(1:10) legend("right",legend="point chart",bg="light green")OutputExample3 Live Demoplot(1:10) legend("left",legend="point chart",bg="light grey")Output

How to increase the width of the median line in boxplot using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:48:53

820 Views

The default width of the median line is wider than the rest of the lines that represent minimum, first quartile, third quartile or maximum but we can make it a little wider to make it more appealing. This can be done with the help of fatten argument inside geom_boxplot function, the default value of fatten is 2.Example Live DemoConsider the below data frame −x

How to change the color of points in a scatterplot using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:45:38

18K+ Views

To color the points in a scatterplot using ggplot2, we can use colour argument inside geom_point with aes. The color can be passed in multiple ways, one such way is to name the particular color and the other way is to giving a range or using a variable. If range or a variable will be used then the color of the points will be in different shades.Example Live DemoConsider the below data frame −x

How to find the unique combinations of a string vector elements with a fixed size in R?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:41:55

1K+ Views

A unique combination of vector elements can be found by using combn function with unique function and size argument will help us to identify the size of each of combination. For example, if we have a vector containing string values defined as x then the unique combinations of vector elements of size 2 can be created by using combn(unique(x),2).Example1 Live Demox1

How to change the font size of main title of boxplot in base R?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:34:42

5K+ Views

The font size of the main title of boxplot can be changed by defining the font size value using par(cex.main=”size”), here size value can be changed based on our requirement. This needs to be done before creating the boxplot, otherwise, there will be no effect on the size of the main title.Example Live Demox

How to find the maximum value in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:31:57

1K+ Views

The maximum value is a part of summary statistics and we always need to understand the end limits of our data; therefore, it is highly required. If we have a data frame that contains numerical columns then the maximum value can be found by using max function and the data frame object name.Example1 Live DemoConsider the below data frame −set.seed(357) x1

How to remove column names from an R data frame?

Nizamuddin Siddiqui
Updated on 05-Feb-2021 08:26:14

10K+ Views

There are situations when we might want to remove column names such as we want to manually replace the existing column names by new names or we simply don’t want to use them if we are very much familiar with the column characteristics. To remove the columns names we can simply set them to NULL as shown in the below examples.Example1Consider the below data frame − Live Demoset.seed(357) x1

Advertisements