Reduce Space Between Y-Axis Values and Ticks Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:21:07

5K+ Views

To reduce the space between axis value and ticks using ggplot2, we can use theme function of ggplot2 package with margin set to 0.For example, if we have a data frame called df that contains two columns say x and y then the scatterplot between x and y with reduced space between Y-axis value and ticks can be created by using the following command −ggplot(df,aes(x,y))+geom_point()+theme(axis.text.y=element_text(margin=margin(r=0)))ExampleFollowing snippet creates a sample data frame −x

Implement Builder Pattern in Kotlin

Soumak De
Updated on 23-Nov-2021 06:17:19

907 Views

In object-oriented programming, the creation of objects is very easy via constructors when the object definitions are simple, but sometimes, it may so happen that the constructors need more variables or functions in order to initialize an object. In such cases, the "builder pattern" comes into picture which helps programmers to create small units of different objects and create a final object.A builder pattern provides an API to construct an object step- by-step.Builder patterns are particularly useful when objects need to be created dynamically.Note that it is not recommended to use builder patterns in Kotlin because we can get the ... Read More

Display Fraction in Base R Plot

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:15:23

2K+ Views

To display fraction in base R plot, we can use frac function in text function.For example, if we create a plot of vectors called X and Y with display of over form fraction as X over Y at X=2 and Y= 2 then we can use the following code −text(2, 2, expression(Output==frac(X, Y)))Check out the below examples to understand how it works.Example 1To display fraction in base R plot, use the code given below −plot(1:5, type="n") text(2, 4, expression(Output==frac(x, y)))OutputIf you execute the above given code, it generates the following output −Example 2To display fraction in base R plot, use ... Read More

Convert Kotlin Source File to Java Source File

Soumak De
Updated on 23-Nov-2021 06:13:27

849 Views

Kotlin is a statistically typed language that runs on JVM. Once a Kotlin file is compiled, it creates a .class file that can be executed on the JVM. In this article, we will see how we can convert a Kotlin source file to a Java source file. In this process, we will be taking help from different online Decompilers available on the Internet.Open VS Code.Go to the "extension" section and install "Kotlin language support for VS Code" and "Code Runner". We need these two extensions to run Kotlin in VS code environment.Install Kotlin compiler in your system as per the ... Read More

Display Fraction in Plot Title Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 06:11:56

1K+ Views

To display fraction in a plot title using ggplot2 in R, we can use frac function inside ggtitle function of ggplot2 package. Generally, fraction is displayed as X/Y but frac function helps to create the fraction in over form.Check out the below example to understand how over form of fraction can be displayed in a plot title using ggplot2.ExampleFollowing snippet creates a sample data frame −x

Find Sequence of Correlation Between Variables in R Data Frame or Matrix

Nizamuddin Siddiqui
Updated on 23-Nov-2021 05:51:00

333 Views

To find the sequence of correlation between variables in an R data frame or matrix, we can use correlate and stretch function from corrr package.For example, if we have a data frame called df then we can find the sequence of correlation between variables in df by using the below given command −df%>% correlate() %>% stretch() %>% arrange(r)Example 1Following snippet creates a sample data frame −x1% + arrange(r) Correlation method: 'pearson' Missing treated using: 'pairwise.complete.obs' # A tibble: 25 x 3OutputIf you execute all the above given snippets as a single program, it generates the following output −  ... Read More

Create Matrix with Vectors as Elements in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 05:45:59

795 Views

To create a matrix with vectors as elements in R, we can create arrays because an array contains matrices with vectors as elements.Check out the below given examples of arrays and vectors extracted by the arrays to understand how matrices stored in an array represent vectors as elements.Example 1Following snippet creates arrays consisting of matrices −Array

Create Vertical Line in Time Series Plot in Base R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 05:42:07

1K+ Views

To create a time series plot, we can use simply apply plot function on time series object and if we want to create a vertical line on that plot then abline function will be used with v argument.For example, if we have a time series object called T and we want to create a time series plot of T with vertical line at point 5 then we can use the below given command after creating the plot −abline(v=5)ExampleTo create a vertical line in a time series plot in base R, use the following code −x

Change the Order of a Matrix Based on a Single Column

Nizamuddin Siddiqui
Updated on 23-Nov-2021 05:40:26

440 Views

To change the order of a matrix in increasing order based on a single column in R, we can use order function after subsetting a particular column.For example, if we have a matrix called M and we want to change the order of M in increasing order based on first column then it can be done by using the following command −M[order(M[,1]),]Example 1Following snippet creates a matrix −M1

Convert Matrices Stored in a List into Vectors in R

Nizamuddin Siddiqui
Updated on 23-Nov-2021 05:34:15

228 Views

A list may contain vectors, data frames, matrices, lists etc. If a list contains matrices and we want to convert those matrices into vectors then lapply function can be used along with as.vector function.For example, if we have a list called LIST that contains matrices then we can convert those matrices into data frames by using the below given command − lapply(LIST,function(x) as.vector(x))ExampleFollowing snippet creates the matrices −M1

Advertisements