You are on page 1of 4

> ?

apply
> X<-matrix(c(1:9), nrow=3, byrow=T)
> apply(x,1,mean)
Error in apply(x, 1, mean) : dim(X) doit avoir un longueur positive
> apply(x,2,mean)
Error in apply(x, 2, mean) : dim(X) doit avoir un longueur positive
> install.packages("ggplot2")
WARNING: Rtools is required to build R packages but is not currently installed.
Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/ASUS/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
essai de l'URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/ggplot2_3.3.3.zip'
Content type 'application/zip' length 4071652 bytes (3.9 MB)
downloaded 3.9 MB

package ‘ggplot2’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\ASUS\AppData\Local\Temp\RtmpE7rHra\downloaded_packages
> library(ggplot2)
> head(diamonds)
# A tibble: 6 x 10
carat cut color clarity depth
<dbl> <ord> <ord> <ord> <dbl>
1 0.23 Ideal E SI2 61.5
2 0.21 Premium E SI1 59.8
3 0.23 Good E VS1 56.9
4 0.29 Premium I VS2 62.4
5 0.31 Good J SI2 63.3
6 0.24 Very Good J VVS2 62.8
# ... with 5 more variables:
# table <dbl>, price <int>,
# x <dbl>, y <dbl>, z <dbl>
> str(diamonds)
tibble [53,940 x 10] (S3: tbl_df/tbl/data.frame)
$ carat : num [1:53940] 0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...
$ cut : Ord.factor w/ 5 levels "Fair"<"Good"<..: 5 4 2 4 2 3 3 3 1 3 ...
$ color : Ord.factor w/ 7 levels "D"<"E"<"F"<"G"<..: 2 2 2 6 7 7 6 5 2 5 ...
$ clarity: Ord.factor w/ 8 levels "I1"<"SI2"<"SI1"<..: 2 3 5 4 2 6 7 3 4 5 ...
$ depth : num [1:53940] 61.5 59.8 56.9 62.4 63.3 62.8 62.3 61.9 65.1 59.4 ...
$ table : num [1:53940] 55 61 65 58 58 57 57 55 61 61 ...
$ price : int [1:53940] 326 326 327 334 335 336 336 337 337 338 ...
$ x : num [1:53940] 3.95 3.89 4.05 4.2 4.34 3.94 3.95 4.07 3.87 4 ...
$ y : num [1:53940] 3.98 3.84 4.07 4.23 4.35 3.96 3.98 4.11 3.78 4.05 ...
$ z : num [1:53940] 2.43 2.31 2.31 2.63 2.75 2.48 2.47 2.53 2.49 2.39 ...
> ?diamonds
> attach(diamonds)
The following objects are masked _by_ .GlobalEnv:

x, y

> qqnorm(depth)
> hist(depth)
> hist(depth, xlab = "diameter des diamonds", col = "yellow", border = "blue")
> hist(depth, xlab = "diameter des diamonds", col = "green", border = "red", xlim =
c(55,65), ylim =
+ c(0,2500), breaks = 2500)
> depthsmall <- sample(depth, 5000)
> shapiro.test(depthsmall)

Shapiro-Wilk normality test

data: depthsmall
W = 0.93474, p-value < 2.2e-16

> x <- seq(-10,10,by = .1)


> y <- dnorm(x, mean = 2.5, sd = 0.5)
> voir pdf il y a l'expression'
Erreur : unexpected symbol in "voir pdf"
> plot(x,y)
> shapiro.test(y)

Shapiro-Wilk normality test

data: y
W = 0.34871, p-value < 2.2e-16

> ?dnorm
> x <- seq(-10,10,by = .2)
> y <- pnorm(x, mean = 2.5, sd = 2)
> plot(x,y)
> shapiro.test(y)

Shapiro-Wilk normality test

data: y
W = 0.75029, p-value = 8.188e-12

> x <- seq(0, 1, by = 0.02)


> y <- qnorm(x, mean = 2, sd = 1)
> plot(x,y)
> shapiro.test(y)

Shapiro-Wilk normality test

data: y
W = NaN, p-value = NA

> y <- rnorm(50)


> hist(y, main = "Normal DIstribution")
> shapiro.test(y)

Shapiro-Wilk normality test

data: y
W = 0.9781, p-value = 0.4747

> boxplot(y, data = rnorm, xlab = "Loi Normale", ylab = " Nombre aleatoire ", main
= "boite a
+ maustache")
> boxplot(y, data = rnorm, xlab = "Loi Normale", ylab = "Nombre aleatoire", main =
"boite a
+ maustache", notch = TRUE, varwidth = TRUE, col = c("green"), names = c("High"))
> mtcars[,c('mpg','cyl')]
mpg cyl
Mazda RX4 21.0 6
Mazda RX4 Wag 21.0 6
Datsun 710 22.8 4
Hornet 4 Drive 21.4 6
Hornet Sportabout 18.7 8
Valiant 18.1 6
Duster 360 14.3 8
Merc 240D 24.4 4
Merc 230 22.8 4
Merc 280 19.2 6
Merc 280C 17.8 6
Merc 450SE 16.4 8
Merc 450SL 17.3 8
Merc 450SLC 15.2 8
Cadillac Fleetwood 10.4 8
Lincoln Continental 10.4 8
Chrysler Imperial 14.7 8
Fiat 128 32.4 4
Honda Civic 30.4 4
Toyota Corolla 33.9 4
Toyota Corona 21.5 4
Dodge Challenger 15.5 8
AMC Javelin 15.2 8
Camaro Z28 13.3 8
Pontiac Firebird 19.2 8
Fiat X1-9 27.3 4
Porsche 914-2 26.0 4
Lotus Europa 30.4 4
Ford Pantera L 15.8 8
Ferrari Dino 19.7 6
Maserati Bora 15.0 8
Volvo 142E 21.4 4
> > boxplot(mpg ~ cyl, data = mtcars, xlab = "Number of Cylinders", ylab = "Miles
Per Gallon", main =
+ "Mileage Data", notch = TRUE, varwidth = TRUE, col =
c("green","yellow","purple"), names =
+ c("High","Medium","Low"))
Warning message:
In bxp(list(stats = c(21.4, 22.8, 26, 30.4, 33.9, 17.8, 18.65, 19.7, :
Quelques indentations ("notches") dépassent des jointures ("hinges") ('box') :
utilisez peut-être notch=FALSE
> summary(mtcars)
mpg cyl
Min. :10.40 Min. :4.000
1st Qu.:15.43 1st Qu.:4.000
Median :19.20 Median :6.000
Mean :20.09 Mean :6.188
3rd Qu.:22.80 3rd Qu.:8.000
Max. :33.90 Max. :8.000
disp hp
Min. : 71.1 Min. : 52.0
1st Qu.:120.8 1st Qu.: 96.5
Median :196.3 Median :123.0
Mean :230.7 Mean :146.7
3rd Qu.:326.0 3rd Qu.:180.0
Max. :472.0 Max. :335.0
drat wt
Min. :2.760 Min. :1.513
1st Qu.:3.080 1st Qu.:2.581
Median :3.695 Median :3.325
Mean :3.597 Mean :3.217
3rd Qu.:3.920 3rd Qu.:3.610
Max. :4.930 Max. :5.424
qsec vs
Min. :14.50 Min. :0.0000
1st Qu.:16.89 1st Qu.:0.0000
Median :17.71 Median :0.0000
Mean :17.85 Mean :0.4375
3rd Qu.:18.90 3rd Qu.:1.0000
Max. :22.90 Max. :1.0000
am gear
Min. :0.0000 Min. :3.000
1st Qu.:0.0000 1st Qu.:3.000
Median :0.0000 Median :4.000
Mean :0.4062 Mean :3.688
3rd Qu.:1.0000 3rd Qu.:4.000
Max. :1.0000 Max. :5.000
carb
Min. :1.000
1st Qu.:2.000
Median :2.000
Mean :2.812
3rd Qu.:4.000
Max. :8.000
> plot(x = mtcars$mpg, y = mtcars$cyl, xlab = "Weight", ylab = "Milage", xlim =
c(10,40), ylim = c(0,10),
+ main = "Weight vs Milage" )
> pairs(~wt+mpg+disp+cyl,data = mtcars, main = "Scatterplot Matrix")
> x <- c(14.8, 81.5, 2.7, 0.4, 1)
> labels <- c("iOS", "Android", "Windows Phone", "BlackBerry", "Autres")
> pie(x,labels)
> pie(x,labels,col = rainbow(length(x)))
> piepercent<- round(100*x/sum(x), 1)
> pie(x, labels = piepercent, main = "Mobile pie chart", col = rainbow(length(x)))
> legend("topright", labels, cex = 0.8, fill = rainbow(length(x)))
> barplot(x)
> barplot(x, names.arg = labels, xlab = "OS", ylab = "nombre utilisateur en
millions", col = "blue", main
+ = "Utilisation mondiale des mobile", border = "red")
> couleurs <- c("green","orange","brown")
> mois <- c("Mars","Avril","Mai","Juin","Juillet")
> regions <- c("Est","Ouest","Nord")
> Values <- matrix(c(2,9,3,11,9,4,8,7,3,12,5,2,8,10,11),nrow = 3,ncol = 5,byrow =
TRUE)
> barplot(Values, main = "revenue total", names.arg = mois, xlab = "mois", ylab =
"revenue", col =
+ couleurs)
> legend("topleft", regions, cex = 1.3, fill = couleurs)

You might also like