Articles on Trending Technologies

Technical articles with clear explanations and examples

How to find the position of minimum of each numerical column if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 232 Views

To find the position of minimum of each numerical column if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the minimum of each numerical column if some columns are categorical.Example 1Create the data frameLet’s create a data frame as shown below −factor1

Read More

How change the color of facet title using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 903 Views

To change the color of facet title using ggplot2 in R, we can use theme function with strip.text.x. argument.For Example, if we have a data frame called df that contains three columns say X, Y and F where F is a factor column then we can create facetted scatterplots between X and Y for values in F having different colored facet title by using the below mentioned command with facet title in different color −ggplot(df, aes(X, Y))+geom_point()+facet_wrap(~F)+theme(strip.text.x=element_text(colour="red"))ExampleFollowing snippet creates a sample data frame −Price

Read More

How to multiply corresponding values from two matrices in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 411 Views

To multiply corresponding values from two matrices in R, we can follow the below steps −First of all, create two matrices.Then, use mapply function to multiply corresponding values from those two matrices.ExampleCreate the first matrixLet’s create a matrix as shown below −M1

Read More

Increase the space between facets in a facetted plot created using ggplot2 in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 4K+ Views

To increase the space between facets in a facetted plot created by using ggplot2 in R, we can use theme function with panel.spacing argument.For Example, if we have a data frame called df that contains three columns say X, Y and F where F is a factor column then we can create facetted scatterplots having facets spaced at a larger distance between X and Y for values in F by using the command given below −ggplot(df, aes(X, Y))+geom_point()+facet_wrap(~F)+theme(panel.spacing=unit(1, "lines"))ExampleFollowing snippet creates a sample data frame −IV

Read More

Change the color of legend element border using ggplot2 in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 4K+ Views

To change the color legend element border using ggplot2, we can use theme function where can put color in legend.key argument to desired color with element_rect.For Example, if we have a data frame called df that contains three columns say X and Y and F where X and Y are numerical and F is categorical then we can create scatterplot between X and Y with blue color of legend element border by using the command given below −ggplot(df, aes(IV, DV))+geom_point(aes(colour=factor(Class)))+theme(legend.key=element_rect(colour="red"))ExampleFollowing snippet creates a sample data frame −IV

Read More

Remove grey color from legend display using ggplot2 in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 4K+ Views

To remove grey color from legend display using ggplot2, we can use theme function where we can fill legend.key argument to white with element_rect.For Example, if we have a data frame called df that contains three columns say X and Y and F where X and Y are numerical and F is categorical then we can create scatterplot between X and Y without grey color in legend display by using the command given below −ggplot(df, aes(X, Y))+geom_point(aes(colour=factor(F)))+theme(legend.key=element_rect(fill="white"))ExampleFollowing snippet creates a sample data frame −x

Read More

How to find the square root of each value in columns if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 333 Views

To find the square root of each value in columns if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the square root of each value in columns if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Level

Read More

How to cover legend in a box using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 2K+ Views

To cover legend in a box using ggplot2 in R, we can use theme function with legend.box.background and legend.box.margin argument. The legend.box.background will have a rectangular element with the help of element_rect and margin values will be set in legend.box.margin.Check out the Example given below to understand how it can be done.ExampleFollowing snippet creates a sample data frame −Score

Read More

How to find the column minimum if some columns are categorical in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 252 Views

To find the column minimum if some columns are categorical in R data frame, we can follow the below steps −First of all, create a data frame.Then, use numcolwise function from plyr package to find the column minimum if some columns are categorical.ExampleCreate the data frameLet’s create a data frame as shown below −Group

Read More

How to display legend on top using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 283 Views

To display legend on top using ggplot2 in R, we can use theme function with legend.justification argument to top.For Example, if we have a data frame called df that contains three columns say X and Y and F where X and Y are numerical and F is categorical then we can create scatterplot between X and Y with point colored by values in F by using the command given below −ggplot(df,aes(X,Y))+geom_point(aes(colour=factor(F)))+theme(legend.justification="top")ExampleFollowing snippet creates a sample data frame −x

Read More
Showing 47481–47490 of 61,299 articles
Advertisements