pacman::p_load(
rio,
here,
tidyverse,
lubridate,
plotly,
gganimate,
ggExtra,
ggalt,
ggcorrplot,
ggpubr,
ggplot2,
zoo,
data.table,
formattable,
tidyr,
ggpmisc, # stat_valey
ggalluvial, # sankey chart
RColorBrewer, # color pattlet
CGPfunctions, # slop graph
ggrepel, # avoid overlap points
ggthemes,
viridis,
dplyr
)
Loading data
df <- import(here("data", "nation.xlsx"))
Worldmap
WorldData <- map_data('world') %>% filter(region != "Antarctica") %>% fortify
p <- ggplot() +
geom_map(data = WorldData, map = WorldData,
aes(x = long, y = lat, group = group, map_id=region),
fill = "white", colour = "#7f7f7f", size=0.5) +
geom_map(data = df, map=WorldData,
aes(fill=value, map_id=region),
colour="#7f7f7f", size=0.5) +
coord_map("rectangular", lat0=0, xlim=c(-180,180), ylim=c(-60, 90)) +
scale_fill_continuous(low = "lightblue",
high = "darkblue") +
scale_y_continuous(breaks=c()) +
scale_x_continuous(breaks=c()) +
labs(fill="", x="", y="") +
theme_bw() +
theme(axis.text = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank(),
panel.background = element_rect(fill = "white"),
plot.title = element_text(hjust = 0.5)
)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in geom_map(data = WorldData, map = WorldData, aes(x = long, y = lat, :
## Ignoring unknown aesthetics: x and y
p

cities <- import(here("data", "mycity.xlsx"))
p + geom_point(data=cities, aes(x=long, y=lat), colour="red", fill="red",pch=21, size=1.5, alpha=I(0.7))

p + geom_point(data=cities, aes(x=long, y=lat, color = city), alpha=I(0.7)) + theme(legend.position = "none")

p + geom_point(data=cities, aes(x=long, y=lat, size = pop), alpha = 0.7)
## Warning: Removed 9 rows containing missing values (`geom_point()`).

p + geom_point(data=cities, aes(x=long, y=lat, size = pop), colour="red", fill="red", alpha= 0.5)
## Warning: Removed 9 rows containing missing values (`geom_point()`).

p + geom_point(data=cities, aes(x=long, y=lat, size = pop), colour="yellow", fill="orange", pch=21, alpha= 0.5)
## Warning: Removed 9 rows containing missing values (`geom_point()`).

p + geom_point(data=cities, aes(x=long, y=lat, color = city, size = pop), alpha=I(0.7)) + theme(legend.position = "none")
## Warning: Removed 9 rows containing missing values (`geom_point()`).

Year of publication
dt <- import(here("output", "output_310523.csv"))
data <- import(here("output", "Book1111.xlsx"))
a <- left_join(data, dt, by='ID')
write.csv(a,'./output/a_year.csv')