|R| Experts
1.08K subscribers
375 photos
35 videos
58 files
204 links
@R_Experts
🔴آمار علم جان بخشیدن به داده‌هاست.
🔷ارتباط با ما
@iamrezaei
لینک یوتیوب و اینستاگرام و ویرگول:
https://zil.ink/expertstv
Download Telegram
#Circle



 draw.circle(...)

function draws a circle on the plot. It's usage is:

draw.circle(x,y,radius,nv=100,border=NULL,col=NA,lty=1,lwd=1)



x,y

: Circle center coordinates
radius

: Circle radius
nv

: Number of vertices
border

: Border Color
col

: Fill Color
lty

: Line type
lwd

: Line width
draw.circle requires "
plotrix

" package, to install:

>install.packages("plotrix")


for #Example

install.packages("plotrix")
plot(BOD)
require(plotrix)
draw.circle(4,14,2,border="blue",col="tan2")


@R_Experts
#Histogram

Is a popular descriptive statistical method that shows data by dividing the range of values into intervals and plotting the frequency/density per interval as a bar.

hist(x, breaks = "Sturges", freq = NULL,  ...)

x

: value vector
breaks

: number of bars
...

for #Example

>x <- read.csv("histogram.csv",header=T,sep="\t")

>x <- t(x)

>ex <- as.numeric(x[2,1:ncol(x)])


Plot a histogram:

>hist(ex)

@R_Experts
The above plot is just a basic histogram. Let's add some parameters:

•br=20, #divide the data into 20 bars
•col="blue", #fill in blue color
•main="Histogram of Expression", #title of the histogram
•xlab="Expression", #x axis description
•ylab="Frequency", #y axis description
•freq=TRUE, #y axis is the frequency of each interval


Here is the command:

>hist(ex,br=14,col="blue",xlab="Expression",ylab="Frequency",
+freq=TRUE,main="Histogram of Expression")


To add a density line into the histogram, we need to change two parameters:

•freq=FALSE, #y axis is the density value of each interval
•ylab="Density", #y axis description as Density


Here is the command:

>hist(ex,br=14,col="blue",xlab="Expression",ylab="Density",freq=FALSE,
+main="Histogram of Expression")
>lines(density(ex),col="red")


We can write the plot into a file:

>png("histogram3.png",400,300)
>hist(ex,br=14,col="blue",xlab="Expression",ylab="Density",
+freq=FALSE,main="Histogram of Expression")
>lines(density(ex),col="red")
>graphics.off()


@R_Experts
#Boxplot
usually refers to box-and-whisker plot, which is a popular method to show data by drawing a box around the 1st and 3rd quartile, and the whiskers for the smallest and largest data values, the median is represented by a bold line in the box.

Following is a csv file example "boxplot.csv", we will draw a boxplot of "Expression" based on Subtype "A", "B" and "C".

Let first read in the data from the file:

> x <- read.csv("boxplot.csv",header=T,sep="\t")
> x <- t(x)
> a <- as.numeric(x[2,1:143])
> b <- as.numeric(x[2,144:218])
> c <- as.numeric(x[2,219:ncol(x)])


Box plot based on subtype A, B and C:

> boxplot(a,b,c,col=c("red","blue","green"),names=c("A","B","C"),
+ xlab="Subtype",ylab="Expression")


The above plot shows that the Expression values for Subtype A, B and C are similar, however the two sub-boxes around the median of Subtype C is wider than B and A, the data are not symmetrically distributed around the median.

if the 'notch' parameter is 'TRUE', a notch is drawn in each side of the boxes. If the notches of two plots do not overlap this is 'strong evidence' that the two medians differ.

> boxplot(a,b,c,col=c("red","blue","green"),names=c("A","B","C"), 
+ notch=TRUE, xlab="Subtype",ylab="Expression")


We can write the plot into a file:

> png("boxplot1.png",400,300)
> boxplot(a,b,c,col=c("red","blue","green"),names=c("A","B","C"),
+ xlab="Subtype",ylab="Expression")
> graphics.off()


@R_Experts
#abline


abline()

function adds a line to plot. It's expression is:

abline(a = NULL, b = NULL, h = NULL, v = NULL, reg = NULL,
coef = NULL, untf = FALSE, ...)



a,b

:Intercept and slope
h

:for horizontal line
v

:for vertical line
...

First let's make a plot:

>x <- c(1.2,3.4,1.3,-2.1,5.6,2.3,3.2,2.4,2.1,1.8,1.7,2.2)
>y <- c(2.4,5.7,2.0,-3,13,5,6.2,4.8,4.2,3.5,3.7,5.2)
>plot(x,y,cex=.8,pch=1,xlab="x",ylab="y",col="black")
>x2 <- c(4.1,1.1,-2.3,-0.2,-1.2,2.3)
>y2 <- c(2.3,4.2,1.2,2.1,-2,4.3)
>points(x2,y2,cex=.8,pch=3,col="blue")


Let's add a red horizontal line at y=4 to the plot:

>abline(h=4,col="red")


Let's add a green vertical line at x=0 to the plot:

>abline(v=0,col="green")

Let's add a blue line with intercept 2 and slope 2 to the plot:

>abline(a=2,b=2,col="blue")


@R_Experts
#پاسخ_تمرین_8
> i<- 10:100
> sum(i^3+4*i^2)
[1] 26852735
>
> rm(list = ls())
>
>
> i <- 1:25
> sum((2^i)/i + 3^i/(i^2))
[1] 2129170437
>



پاسخ ارسالی خانم کاظمی:

> rm(list = ls())
> suma = function(a, b){
+ for(i in a:b){
+ s = i^3 + 4 * i ^ 2
+ }
+ return(s)
+ }
> suma(10, 100)
[1] 1040000
> #b
> sumb = function(a, b){
+ for(i in a:b){
+ s = ((2^i)/ i) + ((3^i)/(i^2))
+ }
+ return(s)
+ }
> sumb(1, 25)
[1] 1357003952
> sumb(1, 25)


ارسالی آقای مزرجی:
> rm(list = ls())
>
> i=0
> for (i in 10:100){
+ a=sum((i^3)+(4×(i^2)))
Error: unexpected input in:
"for (i in 10:100){
a=sum((i^3)+(4×"
> }
Error: unexpected '}' in "}"
> a
Error: object 'a' not found
>
>
> i=0
> for(i in 1:25){
+ b=sum(((2^i)/i)+((3^i)/(i^2)))
+ }
> b
[1] 1357003952
>


با تشکر از زحمات دوستان 🙏🙏🙏

@R_Experts
#R_cmdr

یکی از مشکلات این نرم افزار این است که برخی از کاربران با این زبان و نوشتن دستورات در این برنامه آشنایی ندارند بنابراین خود نرم افزار یک سری پکیچ های مخصوص را برای استفاده ی کاربران مبتدی قرار داده است یک از پر کاربرد ترین این پکیچ ها
 R commander (R cmdr )   

می باشد که یک رابط گرافیگی نرم افزار می باشد.
طریقه نصب این پکیچ مانند سایر پکیچ ها است که هم می توان فایل زیپ آن را دانلود و سپس نصب کرد و یا می توان
با استفاده دستورات تایپ در
"R Console"
ان را نصب کرد
دو روش را به صورت تصویری در شکل های زیر آورده ایم:
@R_Experts