R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

library(rgdal)
## Loading required package: sp
## rgdal: version: 1.3-6, (SVN revision 773)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
##  Path to GDAL shared files: /usr/share/gdal/2.1
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.3-1
library(sf)
## Linking to GEOS 3.5.1, GDAL 2.1.3, PROJ 4.9.2
library(sp)
library(cartography)
library(RColorBrewer)
install.packages("magick")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.5'
## (as 'lib' is unspecified)
library(magick)
## Linking to ImageMagick 6.9.7.4
## Enabled features: fontconfig, freetype, fftw, lcms, pango, x11
## Disabled features: cairo, ghostscript, rsvg, webp
str(magick::magick_config())
## List of 21
##  $ version           :Class 'numeric_version'  hidden list of 1
##   ..$ : int [1:4] 6 9 7 4
##  $ modules           : logi TRUE
##  $ cairo             : logi FALSE
##  $ fontconfig        : logi TRUE
##  $ freetype          : logi TRUE
##  $ fftw              : logi TRUE
##  $ ghostscript       : logi FALSE
##  $ jpeg              : logi TRUE
##  $ lcms              : logi TRUE
##  $ libopenjp2        : logi FALSE
##  $ lzma              : logi TRUE
##  $ pangocairo        : logi TRUE
##  $ pango             : logi TRUE
##  $ png               : logi TRUE
##  $ rsvg              : logi FALSE
##  $ tiff              : logi TRUE
##  $ webp              : logi FALSE
##  $ wmf               : logi TRUE
##  $ x11               : logi TRUE
##  $ xml               : logi TRUE
##  $ zero-configuration: logi FALSE
library(magick)
tiger <- image_read_svg('/cloud/project/literate-and-illiterate-world-population (2).svg', width = 2000)
print(tiger)
##   format width height colorspace matte filesize density
## 1    PNG  2000   1412       sRGB  TRUE        0   72x72

library(magick)
tiger <- image_read_svg('/cloud/project/projections-of-the-rate-of-no-education-based-on-current-global-education-trends-1970-2050 (1).svg', width = 2000)
print(tiger)
##   format width height colorspace matte filesize density
## 1    PNG  2000   1412       sRGB  TRUE        0   72x72

library(magick)
tig <- image_read_svg('/cloud/project/number-of-out-of-school-children.svg', width = 2000)
tig

# load GGplot2
library(ggplot2)

# Create test data.
dat = data.frame(count=c(95, 5), category=c("Primary school completion rate for both sex", "droped out of primary school"))
 
# Add addition columns, needed for drawing with geom_rect.
dat$fraction = dat$count / sum(dat$count)
dat = dat[order(dat$fraction), ]
dat$ymax = cumsum(dat$fraction)
dat$ymin = c(0, head(dat$ymax, n=-1))
 
# Make the plot
p1 = ggplot(dat, aes(fill=category, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) +
     geom_rect() +
     coord_polar(theta="y") +
     xlim(c(0, 4)) +
     theme(panel.grid=element_blank()) +
     theme(axis.text=element_blank()) +
     theme(axis.ticks=element_blank()) +
     annotate("text", x = 0, y = 0, label = "the indicaor of the rate
     of studentS who completd 
     the primary school
     in morocco") +
     labs(title="")
p1

# Define the cars vector with 5 values
studentrate <- c(25, 50, 75, 100)
years <- c(1960,1980,2005,2015)


# Graph the cars vector with all defaults
plot(years,studentrate)

# Define the cars vector with 5 values
#cars <- c(1, 3, 6, 4, 9)
studentrate <- c(25, 50, 75, 100)
years <- c(1960,1980,2005,2015)
# Graph cars using blue points overlayed by a line 
plot(years, studentrate,type="o", col="blue")

# Create a title with a red, bold/italic font
title(main="student inrollement in primary schools in morocco between 1960 and2015", col.main="red", font.main=4)

# Define cars vector with 5 values
studentpergender <- c(57,43 ) 

# Create test data.


# Create a pie chart for cars
pie(studentpergender)

# custom colors and labels
pie(studentpergender, main="student enrollement in primary school per gender in morocco ", col=rainbow(length(studentpergender)),
   labels=c("boys","girls"))

barplot( c(45, 42,68), main="Education expenditure in morocco", xlab="the last three years",ylab="billions Moroccan Dirham")

library(plotrix)
slices <- c(40.99, 43.75, 14.29, 1.08) 
lbls <- c("morocco", "algeria", "tunisia", "muritania")
pie3D(slices,labels=lbls,explode=0.1,
   main="Pie Chart of Countries ")

library(readr)
cr<-read_csv("/cloud/project/API_MAR_DS2_en_csv_v2_10322524.csv")
## Warning: Missing column names filled in: 'X3' [3]
## Parsed with column specification:
## cols(
##   `Data Source` = col_character(),
##   `World Development Indicators` = col_character(),
##   X3 = col_character()
## )
## Warning: 1601 parsing failures.
## row col  expected     actual                                                file
##   2  -- 3 columns 63 columns '/cloud/project/API_MAR_DS2_en_csv_v2_10322524.csv'
##   3  -- 3 columns 63 columns '/cloud/project/API_MAR_DS2_en_csv_v2_10322524.csv'
##   4  -- 3 columns 63 columns '/cloud/project/API_MAR_DS2_en_csv_v2_10322524.csv'
##   5  -- 3 columns 63 columns '/cloud/project/API_MAR_DS2_en_csv_v2_10322524.csv'
##   6  -- 3 columns 63 columns '/cloud/project/API_MAR_DS2_en_csv_v2_10322524.csv'
## ... ... ......... .......... ...................................................
## See problems(...) for more details.
cr
## # A tibble: 1,602 x 3
##    `Data Source`   `World Development In… X3                               
##    <chr>           <chr>                  <chr>                            
##  1 Last Updated D… 2018-11-14             <NA>                             
##  2 Country Name    Country Code           Indicator Name                   
##  3 Morocco         MAR                    Presence of peace keepers (numbe…
##  4 Morocco         MAR                    Intentional homicides (per 100,0…
##  5 Morocco         MAR                    Intentional homicides, male (per…
##  6 Morocco         MAR                    Intentional homicides, female (p…
##  7 Morocco         MAR                    Internally displaced persons, to…
##  8 Morocco         MAR                    Internally displaced persons, ne…
##  9 Morocco         MAR                    Internally displaced persons, ne…
## 10 Morocco         MAR                    Battle-related deaths (number of…
## # … with 1,592 more rows