Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 19 of 196

R Programming how to display both axes’ labels of a ggplot2 graph in italics?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 305 Views

To display both axes’ labels of a ggplot2 graph in italics in R, we can use theme function where we can set the face of axis.text.x and axis.text.y argument to italic.For Example, if we have a data frame called df that contains two columns say X and Y then we can create a scatterplot of X and Y with axes labels in italics by using the below mentioned command −ggplot(df, aes(X, Y))+geom_point()+theme(axis.text.x=element_text(face="italic"), axis.text.y=element_text(face="italic"))ExampleFollowing snippet creates a sample data frame −x

Read More

How to change the color of a particular bar using geom_bar in R?

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

To change the color of a particular bar using geom_bar in R, we can provide the count corresponding to the value for which we want to change the color inside aes function.For Example, if we have a data frame called df that contains two columns say V and F where V is categorical and F is for frequency and we want to change the color of frequency 10 in bar plot then we can use the below mentioned command −ggplot(df, aes(V, F))+geom_bar(aes(fill=..F..==10), stat="identity")ExampleFollowing snippet creates a sample data frame −x

Read More

How to add a value to a particular matrix element in R?

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

To add a value to a particular matrix element in R, we can use subsetting for the particular value with single square brackets.For Example, if we have a matrix called M and we want to add 10 to the fifth value in second column then can use the below mentioned command −M[5,2]

Read More

How to find the number of zeros in each column of an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 11K+ Views

To find the number of zeros in each column of an R data frame, we can follow the below steps −First of all, create a data frame.Then, use colSums function to find the number of zeros in each column.Example 1Create the data frameLet’s create a data frame as shown below −x

Read More

How to multiply corresponding row values in a matrix with single row matrix in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 501 Views

To multiply row values in a matrix having multiple rows with single row matrix in R, we can follow the below steps −First of all, create a matrix with multiple rows and a matrix with single row.Then, use mapply function to multiply row values in those matrices.ExampleCreate the first matrixLet’s create a matrix as shown below −M1

Read More

Check which column names contain a specific string in R data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 5K+ Views

If we have a data frame that contains columns having names with some commong strings then we might want to find those column names. For this purpose, we can use grepl function for subsetting along with colnames function.Check out the Examples given below to understand how it can be done.Example 1Following snippet creates a sample data frame −Students_Score

Read More

How to find the number of zeros in each row of an R data frame?

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

To find the number of zeros in each row of an R data frame, we can follow the below steps −First of all, create a data frame.Then, use rowSums function to find the number of zeros in each row of the data frame.ExampleCreate the data frameLet’s create a data frame as shown below −x

Read More

How to create pivot table with sum for data stored in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 757 Views

To create pivot table with sum for data stored in R data frame, we can follow the below steps −First of all, create a data frame with two categorical and one numerical column.Then, use dcast function from reshape2 package to create pivot table for the data stored in data frame.ExampleCreate the data frameLet’s create a data frame as shown below −Group

Read More

Change the starting point of bars in bar plot for a ggplot2 graph in R.

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

To change the starting point of bars in bar plot for a ggplot2 graph in R, we can use coord_cartesian function of ggplot2 package with ylim argument where we can change the starting and ending point for the bar plot values.Check out the Example given below to understand how it can be done.ExampleFollowing snippet creates a sample data frame −x

Read More

How to increase the length of Y-axis values for ggplot2 graph in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 10-Nov-2021 6K+ Views

To increase the length of Y-axis for ggplot2 graph in R, we can use scale_y_continuous function with limits argument.For Example, if we have a data frame called df that contains two columns say X and Y and we want to have the length of Y-axis starting from 1 to 10 by using the below mentioned command −ggplot(df,aes(X,Y))+geom_point()+scale_y_continuous(limits=c(1,10))ExampleFollowing snippet creates a sample data frame −x

Read More
Showing 181–190 of 1,958 articles
« Prev 1 17 18 19 20 21 196 Next »
Advertisements