R में Line Graph ये plot() इस function का इस्तेमाल किया जाता है | Line Graph में दिए हुए values को point करके line को draw किया जाता है |
Syntax for plot() Function in R
plot(x,type,col,xlab,ylab)
Syntax for plot() Function in R
x : यहाँ पर numeric vector दिया जाता है |
type : character. अगर 'p' दिया जाता है तो सिर्फ points को draw किया जाता है | अगर 'l' दिया जाता है तो सिर्फ line को draw किया जाता है | अगर 'o' दिया जाता है तो points और lines को draw किया जाता है |
col : points और lines को color दिया जाता है |
xlab : x-axis को label दिया जाता है | default x-axis label 'Index' होता है |
ylab : y-axis को label दिया जाता है | default y-axis label 'vector या उसका variable_name' होता है |
xlim : x-axis को limit दी जाती है |
ylim : y-axis को limit दी जाती है |
Simple Example for plot() Function in R
Example पर दिए हुए vector से points दिए गए है |
Source Code :vec = c(12,45,11,58,74) plot(vec)
1.png)
Draw Lines using plot() function's type parameter in R
Example पर points पर lines को draw किया गया है |
Source Code :vec = c(12,45,11,58,74) plot(vec, type = 'o')
2.png)
Remove Points from line graph using type parameter in R
Example पर plot() function के type parameter के 'l' value की मदद से सिर्फ lines को ही draw किया गया है |
Source Code :vec = c(12,45,11,58,74) plot(vec, type = 'l')
3.png)
Color lines using col parameter in R
Example पर plot() function के col parameter से lines को color किया गया है |
Source Code :vec = c(12,45,11,58,74) plot(vec, type = 'l', col = 'green')
4.png)
Add Title, x-axis label and y-axis label in R
Example पर line graph पर title, x-axis label और y-axis label को set किया गया है |
Source Code :vec = c(12,45,11,58,74) plot(vec, type = 'o', col = 'green', xlab = 'X-Axis', ylab = 'Y-Axis', main = 'Line Graph')
5.png)
Draw Multiple line graphs on single plot in R
Example पर lines() function की मदद से multiple line graphs को एक ही plot पर draw किया गया है |
Source Code :vec1 = c(12,45,11,58,74) vec2 = c(45,12,1,87,10) vec3 = c(10,4,15,56,25) plot(vec1, type = 'o', col = 'red', xlab = 'X-Axis', ylab = 'Y-Axis', main = 'Line Graph', ylim = c(0,100)) lines(vec2, type = "o", col = "green") lines(vec3, type = "o", col = "purple")
6.png)