Project

Assignment -4

#plot 1

\"Number_of_Schools-Primary_and_Upper_primary_school.csv\" %>%
read_csv() %>%
clean_names() %>%
filter(india_state_uts != \"India\") %>%
gather(c(3:12),key = year,value=school_count) %>%
separate(year, into = c(\"x\",\"year\"),sep = 1, convert = TRUE) %>%
select(-x) %>%
filter(india_state_uts == \"Meghalaya\" & school_type == \"Upper Primary School\") %>%
ggplot(aes(x= factor(year),
y = school_count,
color = factor(year)
)) +
geom_point(size= 4, shape = 17) +
theme_minimal() +
labs (title = \"Upper Primary schools in Meghalaya\",
y = \"Number of Schools\",
x = \"Year\",
subtitle = \"From data.gov.in\",
caption = \"Yearwise count of Upper Primary schools in Meghalaya\",
colour = \"Year\"
) +
geom_text(aes(label=school_count),hjust=0, vjust=0, check_overlap = TRUE, nudge_y = 1, nudge_x = 0.2 ) +
theme(plot.title = element_text(size = 25, color = \"black\", hjust = 0.5)) +
theme(plot.subtitle = element_text(color = \"black\", hjust = 1, size = 15, face = \"italic\" )) +
theme(legend.position = \"none\") +
theme(axis.text = element_text(colour = \"Black\")) +
theme(axis.ticks = element_line(size = 1)) +
theme(axis.title.y = element_text(size = rel(1.5), face = \"bold\", angle = 90)) +
theme(axis.title.x = element_text(size = rel(1.5), face = \"bold\")) +
theme(
panel.background = element_rect(fill = \"white\"),
plot.margin = margin(0.5, 0.5, 0.5, 0.5, \"cm\"),
plot.background = element_rect(
fill = \"lightgreen\",
colour = \"black\",
size = 1
)
)

#========================================================

# more than one graphs in a single plot
#Plot 2

#plot for Uttar Pradesh

\"Number_of_Schools-Primary_and_Upper_primary_School.csv\" %>%
read_csv() %>%
clean_names() %>%
gather(-c(1:2),key = year,value=school_count) %>%
separate(year, into = c(\"x\",\"year\"), sep = 1, convert = TRUE) %>%
select(-x) %>%
filter(school_type == \"Upper Primary School\" & india_state_uts == \"Uttar Pradesh\") %>%
filter(india_state_uts != \"India\") %>%
drop_na() %>%
ggplot(aes(x = factor(year), y = school_count, fill = factor(year))) +
geom_col() +
#coord_flip() +
labs(title = \" Upper Primary school in UP\",
x = \"Year\",
y = \"Number of Schools\") +
theme(plot.title = element_text(size = 10, color = \"black\", hjust = 0.5)) +
# theme(plot.subtitle = element_text(color = \"black\", hjust = 1, size = 10, face = \"italic\" )) +
theme(axis.text = element_text(colour = \"Black\")) +
theme(axis.ticks = element_line(size = 1)) +
theme(axis.title.y = element_text(size = rel(1), face = \"bold\", angle = 90)) +
theme(axis.title.x = element_text(size = rel(1), face = \"bold\")) +
theme(legend.position = \"none\") +
geom_text(aes(label=school_count),hjust= 0.8, vjust= -0.5, check_overlap = TRUE, nudge_y = 1, nudge_x = 0.2 , size = 2.5) +
theme(
panel.background = element_rect(fill = \"white\"),
panel.spacing = unit(3,\"cm\"),
plot.margin = margin(0.3, 0.3, 0.3, 0.3, \"cm\"),
plot.background = element_rect(
fill = \"white\",
colour = \"black\",
size = 0.3

)
) +coord_cartesian(expand = TRUE) ->UP

#plot for Odisha

\"Number_of_Schools-Primary_and_Upper_primary_School.csv\" %>%
read_csv() %>%
clean_names() %>%
gather(-c(1:2),key = year,value=school_count) %>%
separate(year, into = c(\"x\",\"year\"), sep = 1, convert = TRUE) %>%
select(-x) %>%
filter(school_type == \"Upper Primary School\" & india_state_uts == \"Odisha\") %>%
filter(india_state_uts != \"India\") %>%
drop_na() %>%
ggplot(aes(x = factor(year), y = school_count, fill = factor(year))) +
geom_col() +
#coord_flip() +
labs(title = \" Upper Primary schools in Odisha\",
x = \"Year\",
y = \"Number of Schools\") +
theme(plot.title = element_text(size = 10, color = \"black\", hjust = 0.5)) +
# theme(plot.subtitle = element_text(color = \"black\", hjust = 1, size = 10, face = \"italic\" )) +
theme(axis.text = element_text(colour = \"Black\")) +
theme(axis.ticks = element_line(size = 1)) +
theme(axis.title.y = element_text(size = rel(1), face = \"bold\", angle = 90)) +
theme(axis.title.x = element_text(size = rel(1), face = \"bold\")) +
theme(legend.position = \"none\") +
geom_text(aes(label=school_count),hjust= 0.8, vjust= -0.5, check_overlap = TRUE, nudge_y = 1, nudge_x = 0.2 , size = 2.5) +
theme(
panel.background = element_rect(fill = \"white\"),
panel.spacing = unit(3,\"cm\"),
plot.margin = margin(0.3, 0.3, 0.3, 0.3, \"cm\"),
plot.background = element_rect(
fill = \"white\",
colour = \"black\",
size = 0.3

)
) + coord_cartesian(expand = TRUE)-> Odisha

# plot for Westbengal

\"Number_of_Schools-Primary_and_Upper_primary_School.csv\" %>%
read_csv() %>%
clean_names() %>%
gather(-c(1:2),key = year,value=school_count) %>%
separate(year, into = c(\"x\",\"year\"), sep = 1, convert = TRUE) %>%
select(-x) %>%
filter(school_type == \"Upper Primary School\" & india_state_uts == \"West Bengal\") %>%
filter(india_state_uts != \"India\") %>%
drop_na() %>%
ggplot(aes(x = factor(year), y = school_count, fill = factor(year))) +
geom_col() +
#coord_flip() +
labs(title = \" Upper Primary schools in West Bengal\",
x = \"Year\",
y = \"Number of Schools\") +
theme(plot.title = element_text(size = 10, color = \"black\", hjust = 0.5)) +
# theme(plot.subtitle = element_text(color = \"black\", hjust = 1, size = 10, face = \"italic\" )) +
theme(axis.text = element_text(colour = \"Black\")) +
theme(axis.ticks = element_line(size = 1)) +
theme(axis.title.y = element_text(size = rel(1), face = \"bold\", angle = 90)) +
theme(axis.title.x = element_text(size = rel(1), face = \"bold\")) +
theme(legend.position = \"none\") +
geom_text(aes(label=school_count),hjust= 0.8, vjust= -0.5, check_overlap = TRUE, nudge_y = 1, nudge_x = 0.2 , size = 2.5) +
theme(
panel.background = element_rect(fill = \"white\"),
panel.spacing = unit(3,\"cm\"),
plot.margin = margin(0.3, 0.3, 0.3, 0.3, \"cm\"),
plot.background = element_rect(
fill = \"white\",
colour = \"black\",
size = 0.3

)
) + coord_cartesian(expand = TRUE)->Westbengal

# plot for Rajasthan

\"Number_of_Schools-Primary_and_Upper_primary_School.csv\" %>%
read_csv() %>%
clean_names() %>%
gather(-c(1:2),key = year,value=school_count) %>%
separate(year, into = c(\"x\",\"year\"), sep = 1, convert = TRUE) %>%
select(-x) %>%
filter(school_type == \"Upper Primary School\" & india_state_uts == \"Rajasthan\") %>%
filter(india_state_uts != \"India\") %>%
drop_na() %>%
ggplot(aes(x = factor(year), y = school_count, fill = factor(year),coord_cartesian(0:1, 0:1))) +
geom_col() +
#coord_flip() +
labs(title = \" Upper Primary schools in Rajasthan\",
x = \"Year\",
y = \"Number of Schools\") +
theme(plot.title = element_text(size = 10, color = \"black\", hjust = 0.5)) +
# theme(plot.subtitle = element_text(color = \"black\", hjust = 1, size = 10, face = \"italic\" )) +
theme(axis.text = element_text(colour = \"Black\")) +
theme(axis.ticks = element_line(size = 1)) +
theme(axis.title.y = element_text(size = rel(1), face = \"bold\", angle = 90)) +
theme(axis.title.x = element_text(size = rel(1), face = \"bold\")) +
theme(legend.position = \"none\") +
geom_text(aes(label=school_count),hjust= 0.8, vjust= -0.5, check_overlap = TRUE, nudge_y = 1, nudge_x = 0.2 , size = 2.5) +
theme(
panel.background = element_rect(fill = \"white\"),
panel.spacing = unit(3,\"cm\"),
plot.margin = margin(0.3, 0.3, 0.3, 0.3, \"cm\"),
plot.background = element_rect(
fill = \"white\",
colour = \"black\",
size = 0.3

)
) + coord_cartesian(expand = TRUE)-> Rajasthan

# code for grid plot

theme_set(theme_cowplot(font_size=10))

pgrid <- plot_grid(Rajasthan, Odisha,UP,Westbengal, labels = c(\'A\', \'B\',\'C\',\'D\'))
title <- ggdraw() + draw_label(\"Comparion of Upper Primary school counts in 4 states\", fontface=\'bold\')
plot_grid(title, pgrid, ncol=1, rel_heights=c(0.1, 1))

==================================================

# Plot 3 - using facet_wrap

\"Number_of_Schools-Primary_and_Upper_primary_School.csv\" %>%
read_csv() %>%
clean_names() %>%
gather(-c(1:2),key = year,value=school_count) %>%
separate(year, into = c(\"x\",\"year\"), sep = 1, convert = TRUE) %>%
select(-x) %>%
#filter(year == 2010 & school_type == \"Primary School\") %>%
filter(india_state_uts != \"India\") %>%
drop_na() -> tidydata


tidydata %>%
ggplot(aes(as.factor(year), school_count, fill = factor(year))) +
geom_col() +
facet_wrap(~school_type, scales = \"free_y\") +
labs (x= \"Year\",
y = \"Number of Schools\") +
theme(axis.text = element_text(colour = \"Black\")) +
theme(axis.ticks = element_line(size = 1)) +
theme(axis.title.y = element_text(size = rel(1.2), face = \"bold\", angle = 90)) +
theme(axis.title.x = element_text(size = rel(1.2), face = \"bold\")) +
theme(legend.position = \"none\") +
ggtitle(\"Primary Schools Vs Upper Primary Schools\")

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.