Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1444 of 2650
3K+ Views
To display characters inside a base R plot we can simply use text function with expression and if we want to display an asterisk then we need to put the asterisk within double quotes. For example, if we want to display three stars then only expression(paste("***"))) should be used. Check out the below examples to understand how it works.Example1> plot(1:10,type="n") > text(8,9,expression(paste(Sig.^"***")))OutputExample2> plot(1:10,type="n") > text(5,6,expression(paste(Less_Sig.^"**")))OutputExample3> plot(1:10,type="n") > text(2,3,expression(paste(Very_Less_Sig.^"**")))Output
1K+ Views
There are multiple ways to create a bar plot in R and one such way is using stat_summary of ggplot2 package. In this function, we need to supply a function for the y-axis and to create the bars we must use geom="bar". The main thing is to decide which function should be used for y-axis values.ExampleConsider the below data frame:Live Demo> x y df dfOutput x y 1 Female 3 2 Male 3 3 Female 7 4 Male 3 5 Female 8 6 Female 5 7 Male 11 8 Male 6 9 Male 5 ... Read More
354 Views
A heatmap is a diagrammatic representation of data where the values are represented with colours. Mostly, it is used to display data that has slight variation and applied on matrix data. We can draw it for a full matrix, an upper triangular matrix as well as a lower triangular matrix. This can be done with the help of image function.Example1Live Demo> M MOutput [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 7 5 4 4 3 6 5 8 3 5 [2,] 8 7 3 5 7 4 5 2 6 6 [3,] 3 2 4 2 5 12 7 3 10 2 [4,] 5 3 6 9 5 9 2 4 5 8 [5,] 3 8 5 5 4 4 4 1 2 5 [6,] 2 3 2 4 7 8 5 8 4 4 [7,] 5 6 4 4 7 3 4 8 8 2 [8,] 4 5 2 10 5 3 5 4 6 7 [9,] 8 6 4 1 4 11 6 4 6 6 [10,] 9 5 5 4 6 2 7 3 6 5Example> image(M)Output:Example2Live Demo> M1 M1Output [,1] [,2] [,3] [,4] [,5] [,6] [1,] 24.75339 25.40680 23.76650 26.47724 24.54639 25.79895 [2,] 24.08571 25.17951 25.03599 25.63532 23.45812 25.39614 [3,] 24.53005 25.77095 26.21571 24.44029 24.69933 25.62839 [4,] 22.91202 25.49497 24.86587 25.25701 23.16166 24.34106 [5,] 25.37322 24.15308 25.58580 23.52173 25.25538 25.10577 [6,] 24.39613 26.06243 26.56054 25.19265 26.54187 24.35313Example> image(M1)Output:
135 Views
The axes widths are generally very thin in plots but we can make them wider. This will be useful if we want to highlight the axes labels for reasons such as getting attention of the viewer on axes labels etc. To increase the width of the axes in a base R plot, we can use axis function and set the lwd argument.Example> x hist(x) > axis(side=1,lwd=4)Output:Example> axis(side=2,lwd=4)Output:
895 Views
The na.omit function removes all the missing values in a data frame and complete.cases also does the same thing if applied to the whole data frame. The main difference between the two is that complete.cases can be applied to some columns or rows. Check out the below example to understand the difference.ExampleConsider the below data frame:Live Demo> set.seed(2584) > x y df dfOutput x y 1 NA 25 2 5 5 3 8 NA 4 6 5 5 4 NA 6 4 5 7 6 NA 8 4 NA 9 4 5 10 8 5 11 8 5 ... Read More
3K+ Views
The names of list elements can be extracted by using the names function. For example, if we have a list defined as List that contains three elements with names element1, element2, and element3 then then these names can be extracted from the List by using the below command:names(List)Example1Live Demo> List1 List1Output$x1 [1] -0.04518909 -0.22779868 0.24339595 -0.86189295 -0.73387277 -0.75313131 [7] 0.39694608 2.30565359 0.55670193 0.21973762 0.62968128 -0.90936921 [13] 1.33946741 -0.16315751 0.31357793 0.40365980 -0.23639612 -2.48749453 [19] 0.52152768 -1.57059863 0.51728464 0.98177111 0.65475629 0.23715538 [25] -0.71796609 -0.42731839 0.32335282 -0.90013122 -0.84549927 -0.88358214 [31] -0.32066379 -0.98945433 0.42469849 -1.63095343 0.32584448 0.10947333 [37] 0.23486625 0.28166351 1.18432843 0.94828212 0.09452671 0.56618262 ... Read More
927 Views
A heatmap is a diagrammatic representation of data where the values are represented with colours. Mostly, it is used to display data that has slight variation. We can draw it for a full matrix, an upper triangular matrix as well as a lower triangular matrix. This can be done with the help of image function.Example1Live Demo> M1 M1Output [, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [1, ] 6 9 4 7 5 4 [2, ] 6 6 4 3 7 5 [3, ] 2 ... Read More
437 Views
If we have a data frame defined as df that contains column x, y, and z then extraction of these columns from df can be done by using df$x, df$y, and df$z. On the other hand, if we have an S4 object defined as Data_S4 that contains column x, y, and z then the extraction of these columns can be done by using Data_S4@x, Data_S4@y, and Data_S4@z.Example of a data frame:ExampleLive Demo> x1 x2 df dfOutput x1 x2 1 4 2 2 7 0 3 10 2 4 3 1 5 7 1 6 2 2 7 3 4 8 ... Read More
861 Views
By default, a histogram drawn in base R has black color borders around bars. We might want to remove these black borders to make the histogram visually smooth. This can be done by using lty argument with the hist function. For example, if we have a vector x and we want to create a histogram of x without border of bars then we can use the argument as hist(x,lty="blank").Example> x hist(x)Output:Creating histogram of x without border of bars:Example> hist(x,lty="blank")Output:
2K+ Views
To create an S4 object, we can use setClass function where we will pass the object name, column names, and the type of the data that will be stored in the columns. For example, if we want to create an S4 with name data and two numerical columns called by x and y then we can use setClass("data", representation(x1="numeric", x2="numeric")).Example1> setClass("data1", representation(x1="numeric", x2="numeric")) > data1 data1OutputAn object of class "data1" Slot "x1": [1] -0.586187627 0.853689097 -0.602612795 -2.194235741 -1.318522292 [6] -0.984882420 0.273584140 0.364691611 1.025472248 1.198547297 [11] -0.709282551 -0.001441127 -0.201348012 1.296811172 1.520093861 [16] 2.071031215 0.472877022 0.616211695 0.642165615 -0.122773000 Slot "x2": [1] ... Read More