|R| Experts
1.08K subscribers
375 photos
35 videos
58 files
204 links
@R_Experts
🔴آمار علم جان بخشیدن به داده‌هاست.
🔷ارتباط با ما
@iamrezaei
لینک یوتیوب و اینستاگرام و ویرگول:
https://zil.ink/expertstv
加入频道
#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)
#Example

#Step_1


First let's make a simple bar chart:

>x <- c(3,2,6,8,4)
>barplot(x)


#Step_2


Let's add some annotations:

>barplot(x,border="tan2",names.arg=c("Jan","Feb","Mar","Apr","May"),
+ xlab="Month",ylab="Revenue",density=c(0,5,20,50,100))



#Step_3

Suppose the bar chart above is about software department of our company, we are going to compare other department's revenues including hardware and services:

>A <- matrix(c(3,5,7,1,9,4,6,5,2,12,2,1,7,6,8),nrow=3,ncol=5,byrow=TRUE)
>barplot(A,main="total revenue",names.arg=c("Jan","Feb","Mar","Apr","May"),
+ xlab="month",ylab="revenue",col=c("tan2","blue","darkslategray3"))
>legend(x=0.2,y=24,c("soft","hardware","service"),cex=.8,
+ col=c("tan2","blue","darkslategray3"),pch=c(22,0,0))



#Step_4

Let's compare the data sets horizontally:

>barplot(A,main="total revenue",beside=TRUE,
+ names.arg=c("Jan","Feb","Mar","Apr","May"),
+ xlab="month",ylab="revenue",col=c("tan2","blue","darkslategray3"))
>legend(x=1,y=11,c("soft","hardware","service"),cex=.8,
+ col=c("tan2","blue","darkslategray3"),pch=c(22,0,0))


@R_Experts