Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 123 of 196

How to display legend on top using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 09-Nov-2021 201 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

How to change the text size of Y-axis title using ggplot2 in R?

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

By default, the text size of axes titles are small but if we want to increase that size so that people can easily recognize them then theme function can be used where we can use axis.title.y argument for Y-axis and axis.title.x argument for X-axis with element_text size to larger value.Check out the Example given below to understand how it can be done.ExampleFollowing snippet creates a sample data frame −Country

Read More

How to increase the axes tick width using ggplot2 in R?

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

To increase the width of axes tick (both X-axis and Y-axis at the same time) using ggplot2 in R, we can use theme function with axis.ticks argument where we can set element_line argument size to a larger value.For Example, if we have a data frame called df that contains a single column X and we want to create histogram of X with wider axes ticks then we can use the command given below −ggplot(df,aes(X))+geom_histogram(bins=30)+theme(axis.ticks=element_line(size=2))ExampleFollowing snippet creates a sample data frame −x

Read More

How to increase the width of axes using ggplot2 in R?

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

To increase the width of axes (both X-axis and Y-axis at the same time) using ggplot2 in R, we can use theme function with axis.line argument where we can set element_line argument to a larger value.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 convert first letter into capital in single column data frame in R using dplyr?

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

To convert first letter into capital in single column data frame in R, we can follow the below steps −First of all, create a data frame with string column.Then, use sub function along with mutate function of dplyr package to convert first letter into capital in string column.ExampleCreate the data frameLet’s create a data frame as shown below −Names

Read More

How to change the border style of a plot using ggplot2 in R?

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

To change the border style of a plot using ggplot2 in R, we can use theme function with panel.border argument where we can change the linetype for the plot border using element_rect. There are many linetypes and we can use them as desired.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 extract the first n values of all elements of a list in R?

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

To extract the first n values of all elements of a list in R, we can follow the below steps −First of all, create a list.Then, use head function with sapply function to extract the first n values of all elements in the list.Example 1Create the listLet’s create a list as shown below −List1

Read More

Find the column name that contains value greater than a desired value in each row of an R data frame.

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

To find the column name that contains value greater than a desired value in each row of an R data frame, we can use apply function along with lapply function.For Example, if we have a data frame called df and we want to extract column names for each row having values greater than 5 then we can use the command given below −lapply(apply(df,1, function(x) which(x5)),names)Example 1Following snippet creates a sample data frame −x1

Read More

How to extract the last value of all elements of a list in R?

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

To extract the last value of all elements of a list in R, we can follow the below stepss −First of all, create a list.Then, use tail function with sapply function to extract the last value of all elements in the list.Example 1Create the listLet’s create a list as shown below −List

Read More

How to repeat a whole data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Nov-2021 938 Views

To repeat a whole data.table object in R, we can follow the below steps −First of all, create a data.table object.Then, use rep function to repeat the data.table object.ExampleCreate the data.table objectLet’s create a data.table object as shown below −library(data.table) x

Read More
Showing 1221–1230 of 1,958 articles
« Prev 1 121 122 123 124 125 196 Next »
Advertisements