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
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)
# 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 ")
# Read in csv files
df <- read.table("https://s3.amazonaws.com/assets.datacamp.com/blog_assets/test.csv",
header = FALSE,
sep = ",")
df <- read.csv("https://s3.amazonaws.com/assets.datacamp.com/blog_assets/test.csv",
header = FALSE)
df <- read.csv2("https://s3.amazonaws.com/assets.datacamp.com/blog_assets/test.csv",
header= FALSE)
# Inspect the result
df
## V1
## 1 Col1,Col2,Col3
## 2 1,2,3
## 3 4,5,6
## 4 7,8,9
## 5 a,b,c
library(readr)
fr<-read_csv("/cloud/project/G4DASS2/primary-school-attendance-selected-countries (1).csv")
## Parsed with column specification:
## cols(
## Entity = col_character(),
## Code = col_character(),
## Year = col_double(),
## `UIS: Net attendance rate, primary, both sexes (%) (%)` = col_double()
## )
fr
## # A tibble: 127 x 4
## Entity Code Year `UIS: Net attendance rate, primary, both sexes …
## <chr> <chr> <dbl> <dbl>
## 1 Afghanistan AFG 2011 51.5
## 2 Albania ALB 2009 91.4
## 3 Armenia ARM 2006 81.3
## 4 Armenia ARM 2011 93.6
## 5 Azerbaijan AZE 2006 87.8
## 6 Bangladesh BGD 2006 75.9
## 7 Bangladesh BGD 2011 83.1
## 8 Belize BLZ 2006 88.1
## 9 Benin BEN 2006 64.7
## 10 Benin BEN 2011 68.7
## # … with 117 more rows
library(readr)
cr<-read_csv("/cloud/project/G4DASS2/population-breakdown-by-highest-level-of-education-achieved-for-those-aged-15-in (1).csv")
## Parsed with column specification:
## cols(
## Entity = col_character(),
## Code = col_character(),
## Year = col_double(),
## `1. Population aged 0-14` = col_double(),
## `2. No education` = col_double(),
## `3. Primary` = col_double(),
## `4. Secondary` = col_double(),
## `5. Tertiary` = col_double()
## )
cr
## # A tibble: 2,533 x 8
## Entity Code Year `1. Population … `2. No educatio… `3. Primary`
## <chr> <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Argen… ARG 1970 7031590 1690426. 10637607.
## 2 Argen… ARG 1975 7607850 1576489. 11203801.
## 3 Argen… ARG 1980 8571100 1436029. 11428848.
## 4 Argen… ARG 1985 9392290 1306083. 11682710.
## 5 Argen… ARG 1990 10012300 1179670. 11908364.
## 6 Argen… ARG 1995 10145530 1060750. 12207107.
## 7 Argen… ARG 2000 10308390 947201. 12315110.
## 8 Argen… ARG 2005 10178170 835887. 12263503.
## 9 Argen… ARG 2010 10050060 729728. 12121773.
## 10 Argen… ARG 2015 10003060 630038. 11750805.
## # … with 2,523 more rows, and 2 more variables: `4. Secondary` <dbl>, `5.
## # Tertiary` <dbl>
library(readr)
cr<-read_csv("/cloud/project/G4DASS2/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/G4DASS2/API_MAR_DS2_en_csv_v2_10322524.csv'
## 3 -- 3 columns 63 columns '/cloud/project/G4DASS2/API_MAR_DS2_en_csv_v2_10322524.csv'
## 4 -- 3 columns 63 columns '/cloud/project/G4DASS2/API_MAR_DS2_en_csv_v2_10322524.csv'
## 5 -- 3 columns 63 columns '/cloud/project/G4DASS2/API_MAR_DS2_en_csv_v2_10322524.csv'
## 6 -- 3 columns 63 columns '/cloud/project/G4DASS2/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
install.packages("magick")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.5'
## (as 'lib' is unspecified)
## Warning in install.packages("magick"): installation of package 'magick' had
## non-zero exit status
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/G4DASS2/literate-and-illiterate-world-population (2).svg', width = 2000)
print(tiger)
## # A tibble: 1 x 7
## format width height colorspace matte filesize density
## <chr> <int> <int> <chr> <lgl> <int> <chr>
## 1 PNG 2000 1412 sRGB TRUE 0 72x72