0% found this document useful (0 votes)
12 views3 pages

Ggplot

Uploaded by

dixitmuskan635
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Ggplot

Uploaded by

dixitmuskan635
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Untitled

Muskan

2024-11-14

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.
install.packages(“ggplot2”) library(ggplot2) data<-read.csv(“C:\Users\
HP5CD\Downloads\Economist_Assignment_Data.csv”)
head(data)
p1<-ggplot(data,aes(x=CPI,y=HDI,color=Region)) + geom_point() p1
p1<-ggplot(data,aes(x=CPI,y=HDI,color=Region)) +
geom_point(size=4,shape=1) p1
p1+geom_smooth(aes(group=1))
p2<-
p1+geom_smooth(aes(group=1),method=‘lm’,formula=y~log(x),se=FALSE,
color=‘red’) p2
p2+geom_text(aes(label=Country))
pointsToLabel <- c(‘Russia’, ‘Venezuela’, ‘Iraq’, ‘Myanmar’, ‘Sudan’,
‘Afghanistan’, ‘Congo’, ‘Greece’, ‘Argentina’, ‘Brazil’, ‘India’, ‘Italy’, ‘China’,
‘South Africa’, ‘Spain’, ‘Botswana’, ‘Cape Verde’, ‘Bhutan’, ‘Rwanda’,
‘France’, ‘United States’, ‘Germany’, ‘Britain’, ‘Barbados’, ‘Norway’, ‘Japan’,
‘New Zealand’, ‘Singapore’)
p3 <- p2 + geom_text(aes(label=Country), color= ‘gray20’,
data=subset(data, Country %in% pointsToLabel), check_overlap = TRUE)
p3
p4<-p3+ theme_bw() p4
p5<-p4 + scale_x_continuous(name=“corruption perceptions
index,2011(10=least corrupt)”,limits=c(0.9,10.5),breaks=1:10) p5
p6<-p5 + scale_y_continuous(name=“Human development
index,2011(1=best)”,limits=c(0.2,1,0)) p6
p6+ggtitle(‘Corruption and Human development’)
library(ggthemes) p6+theme_economist_white()

You might also like