Create a Black and White Word Cloud in R

Nizamuddin Siddiqui
Updated on 14-Oct-2020 11:28:18

195 Views

According to Google, a word cloud is an image composed of words used in a particular text or subject, in which the size of each word indicates its frequency or importance. In R, we can create word cloud by using wordcloud function of wordcloud package. So, we have the same name of the function as the package, thus we should not get confused by it.Loading wordcloud package and creating a wordcloud −library("wordcloud") x

Convert Repeated Strings in a Vector to Unique Elements in R

Nizamuddin Siddiqui
Updated on 14-Oct-2020 11:25:20

188 Views

When we have repeated elements of strings and we want to use them as factor levels then it is okay but if we want to treat them individually then it is better to make each value a unique element. To do this, we can use make.unique function. For example, if we have a vector x that contains repeated string values then to make them unique, we can use make.unique(x).Example Live Demox1

Create Stacked Bar Plot with Vertical Bars in R Using ggplot2

Nizamuddin Siddiqui
Updated on 14-Oct-2020 11:17:31

552 Views

Traditionally, the stacked bar plot has multiple bars for each level of categories lying upon each other. But this visual can be changed by creating vertical bars for each level of categories, this will help us to read the stacked bar easily as compared to traditional stacked bar plot because people have a habit to read vertical bars.Consider the below data frame −Example Live Demoset.seed(999) Class

Subtract One Data Frame from Another in R

Nizamuddin Siddiqui
Updated on 14-Oct-2020 11:12:46

10K+ Views

If we have two data frames with same number of columns of same data type and equal number of rows then we might want to find the difference between the corresponding values of the data frames. To do this, we simply need to use minus sign. For example, if we have data-frames df1 and df2 then the subtraction can be found as df1-df2.Consider the below data frame −Example Live Demox1

Create Unordered Combination of Elements in String Vector in R

Nizamuddin Siddiqui
Updated on 14-Oct-2020 10:05:56

208 Views

An unordered combination of elements means that the combination of the values in a way that does not make any particular arrangement. For example, if we have three values one, two, and three then they can be arranged in the following way which is unordered −"one" "two" "three" "one" "two" "one" three" "two" "three" "one" "two" "three"Example Live Demox

Check Leap Year or Vector of Years in R

Nizamuddin Siddiqui
Updated on 14-Oct-2020 10:04:26

443 Views

Almost everyone knows that a leap has 366 instead of 365 days and it occurs once in four years. If we want to check whether a particular year is a leap year or in a range of years which years correspond to leap year then we can use leap_year function of leap year. The length function can be used with the year value and if the output is 1 then it will be a leap year otherwise the output will be 0 which refers to the non-leap year.Loading lubridate package −Examplelibrary("lubridate") year1

Change Title of a Graph to Italic in R Using Plot Function

Nizamuddin Siddiqui
Updated on 14-Oct-2020 09:59:46

299 Views

If a graph is created by specifying main title of the plot using the plot function then the default font is plain text. We might want to change the style of the font to italic so that the title gets a little more attraction of the viewers. This can be done by using font.main argument with plot function. The value 4 of font.main refers to the bold italic font and if we want to make it bold then we can use the value 3.Consider the below vectors and create the scatterplot between the two with title of the plot −ExamplexRead More

Round Correlation Values in R to Zero Decimal Places

Nizamuddin Siddiqui
Updated on 14-Oct-2020 09:57:20

4K+ Views

To find the correlation matrix, we simply need to use cor function with the data frame object name. For example, if we have a data frame named as df then the correlation matrix can be found by using cor(df). But the result will have too many decimal places to represent the correlation. If we want to avoid the values after decimal places, we can use round function.Consider the mtcars data in base R −Example Live Demodata(mtcars) cor(mtcars)Output      mpg           cyl        disp        hp         drat     ... Read More

Find Root Mean Square of a Vector in R

Nizamuddin Siddiqui
Updated on 14-Oct-2020 09:40:27

818 Views

To find the root mean square of a vector we can find the mean of the squared values then take the square root of the resulting vector. This can be done in a single and very short line of code. For example, if we have a vector x and we want to find the root mean square of this vector then it can be done as sqrt(mean(x^2)).Example Live Demox1

Create Blue or Red Colored Boxplots in R using ggplot2

Nizamuddin Siddiqui
Updated on 14-Oct-2020 09:38:22

226 Views

The default color of boxplot area in R using ggplot2 is white but we might want to change that color to something more attracting, for example blue or red. To do this purpose, we can use geom_boxplot function of ggplot2 package with fill argument by passing the color names.Consider the below data frame −Example Live Demoset.seed(1321) v1

Advertisements