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


par("bg=blue4")
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
main = "rpois(100, lambda = 5)")


در این مثال

type="h"


نوع نمودار به فرم هیستوگرامی را مشخص

col="red"


رنگ میله ها

lwd=10


پهنای میله ها

main = "rpois(100, lambda = 5)"


عنوان نمودار در بک گراند میباشد


@R_Experts
#Example_2

par(bg="gold")
attach(mtcars)
plot(wt, mpg, main="Scatterplot Example",
xlab="Car Weight ", ylab="Miles Per Gallon ", pch=20)


نمودار پراکنش مربوط به داده های

mtcars


xlab=" " ,ylab=" "


برچسب های محورها

pch=" "


نوع شکل نقطه ها

را تعیین میکنند

@R_Experts
#سرگرمی


par(bg="gold")
n = 17

theta = seq(0, 2 * pi, length = n + 1)[1:n]

x = sin(theta)

y = cos(theta)

v1 = rep(1:n, n)

v2 = rep(1:n, rep(n, n))

plot.new()

plot.window(xlim = c(-1, 1),
ylim = c(-1, 1), asp = 1)

segments(x[v1], y[v1], x[v2], y[v2])



@R_Experts
#Example_3
ی مثال خوب و سطح بندی شده:
#Step_1

# Define the cars vector with 5 values

cars <- c(1, 3, 6, 4, 9)


# Graph the cars vector with all defaults

plot(cars)




#Step_2

# Define 2 vectors

cars <- c(1, 3, 6, 4, 9)

trucks <- c(2, 5, 4, 5, 12)


# Graph cars using a y axis that ranges from 0 to 12

plot(cars, type="o", col="blue", ylim=c(0,12))


# Graph trucks with red dashed line and square points

lines(trucks, type="o", pch=22, lty=2, col="red")


# Create a title with a red, bold/italic font

title(main="Autos", col.main="red", font.main=4)



#Step_3

# Define 2 vectors

cars <- c(1, 3, 6, 4, 9)

trucks <- c(2, 5, 4, 5, 12)


# Calculate range from 0 to max value of cars and trucks

g_range <- range(0, cars, trucks)


# Graph autos using y axis that ranges from 0 to max 

# value in cars or trucks vector.  Turn off axes and 

# annotations (axis labels) so we can specify them ourself

plot(cars, type="o", col="blue", ylim=g_range, 

   axes=FALSE, ann=FALSE)


# Make x axis using Mon-Fri labels

axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri"))


# Make y axis with horizontal labels that display ticks at 

# every 4 marks. 4*0:g_range[2] is equivalent to c(0,4,8,12).

axis(2, las=1, at=4*0:g_range[2])


# Create box around plot

box()


# Graph trucks with red dashed line and square points

lines(trucks, type="o", pch=22, lty=2, col="red")


# Create a title with a red, bold/italic font

title(main="Autos", col.main="red", font.main=4)


# Label the x and y axes with dark green text

title(xlab="Days", col.lab=rgb(0,0.5,0))

title(ylab="Total", col.lab=rgb(0,0.5,0))


# Create a legend at (1, g_range[2]) that is slightly smaller 

# (cex) and uses the same line colors and points used by 

# the actual plots 

legend(1, g_range[2], c("cars","trucks"), cex=0.8, 

   col=c("blue","red"), pch=21:22, lty=1:2)
#Step_2

همان طور که مشاهده میکنید
دو بردار را تعریف کرده
ابتدا با دستور

polt


نمودار آبی را رسم

(دستورات قبلا توضیح داده شده) و

ylim=c( )


حدود محور y ها را تعیین میکند

سپس با دستور

lines


که برای رسم نمودار های خطی به کار میرود نمودار قرمز را رسم و با

title( )


بر چسبی به رنگ قرمز با فونت 4 با مضمون

main="Autos"


به آن داده ایم


@R_Experts
#Step_3

دو بردار را تعریف کرده

سپس با تابع

range( )


دامنه محور هامون رو از صفر تا ماکزیمم مقادیر اون بردارها در نظر گرفته ایم

با دستور پلات نمودار را رسم و با

axis( )


روی محور x ها را به 5 قسمت مساوی تقسیم و از دوشنبه تا جمعه را به آنها اختصاص داده ایم

و بر روی محور y ها نیز همین کار را تکرار با این تفاوت که اندازه فاصله متوالی بین دو نقطه روی این محور دو برابر فاصله محور x میباشد

سپس جعبه ای برای این نمودار طراحی

box( )


و در ادامه دستور رسم نمودار

lines ( )


و بر روی بک گراند و محور ها برچسبی را طراحی و در اخر

راهنمای نمودار را داخل باکس قرار داده ایم که درباره ی این دستور بحث جداگانه ای را خواهیم داشت


@R_Experts
#legend ( )

legend(x, y = NULL, legend, fill = NULL, col = par("col"),
border = "black", lty, lwd, pch,
angle = 45, density = NULL, bty = "o", bg = par("bg"),
box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"),
pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,
xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1,
adj = c(0, 0.5), text.width = NULL, text.col = par("col"),
text.font = NULL, merge = do.lines && has.pch, trace = FALSE,
plot = TRUE, ncol = 1, horiz = FALSE, title = NULL,
inset = 0, xpd, title.col = text.col, title.adj = 0.5,
seg.len = 2)

این دستور برای ایجاد راهنما یا برچسب در داخل نمودار ،
مورد استفاده قرار میگیرد که شامل آرگومان های مختلفی است که به ذکر چند مورد میپردازیم :


شروع این دستور با x,y خواهد بود که مختصات برچسب شما را
داخل یک باکس تعیین میکند که طول و عرض آن مستطیل حداکثر
در کجای محور مختصلت قرار گیرد .

در دستور

fill


نوع برچسب یا راهنمای نمودار خود را نوشته

در

col

نوع رنگ را تعیین
و در

pch 


نوع شکل نقاط را مشخص میکنیم

cex


اندازه فونت نوشته را مشخص
و
border


که رنگ باکس راهنما میباشد که به طور پیش فرض مشکی است میتواند تغیییر کند .

@R_Experts
#Example

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)

plot(x,y,cex=.8,pch=1,xlab="x",ylab="y",col="black")

points(x2,y2,cex=.8,pch=3,col="blue")

legend(x=-2,y=12,c("sample","control"),cex=.8, 

        col=c("black","blue"),pch=c(1,3))


@R_Experts
 barplot(...)

funtion plot a bar chart. It's usage is:

barplot(height, width = 1, space = NULL,
names.arg = NULL, legend.text = NULL, beside = FALSE,
horiz = FALSE, density = NULL, angle = 45,
col = NULL, border = par("fg"),
main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL, xpd = TRUE, log = "",
axes = TRUE, axisnames = TRUE,
cex.axis = par("cex.axis"), cex.names = par("cex.axis"),
inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0,
add = FALSE, args.legend = NULL, ...)



height

: Vector of each bar heights
width

: Vector of bar width
space

: Space between bars
col

: Vector of color for each bar
...

@R_Experts