## # A tibble: 6 x 30
## inpution Panel Tinh_old Tinh Year gGDP GDPP LnGDPP1 LnGDPP2 LnGDPP3
## <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 An G~ An Giang AnGi~ 2010 9.36 18118. 9.80 9.80 9.80
## 2 1 An G~ An Giang AnGi~ 2011 6.93 22999. 10.0 10.0 10.0
## 3 1 An G~ An Giang AnGi~ 2012 4.67 23773. 10.1 10.1 10.1
## 4 1 An G~ An Giang AnGi~ 2013 4.73 25616. 10.2 10.2 10.2
## 5 1 An G~ An Giang AnGi~ 2014 4.87 27797. 10.2 10.2 10.2
## 6 1 An G~ An Giang AnGi~ 2015 5.04 29590. 10.3 10.3 10.3
## # ... with 20 more variables: LnGDPP4 <dbl>, LnGDPP5 <dbl>, GDPHH <dbl>,
## # LnGDPH <dbl>, plZone <dbl>, Zonenam <chr>, plArea <dbl>, Mien <chr>,
## # plGDP <dbl>, plPCI <dbl>, PCI <dbl>, CSTP1 <dbl>, CSTP2 <dbl>, CSTP3 <dbl>,
## # CSTP4 <dbl>, CSTP5 <dbl>, CSTP7 <dbl>, CSTP8 <dbl>, CSTP9 <dbl>,
## # CSTP10 <dbl>
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## `summarise()` ungrouping output (override with `.groups` argument)
## # A tibble: 6 x 4
## Tinh tbPCI plPCI ploai
## <chr> <dbl> <dbl> <chr>
## 1 DakNong 54.1 -5.84 Duoi
## 2 CaoBang 55.0 -4.89 Duoi
## 3 LaiChau 55.4 -4.47 Duoi
## 4 HaGiang 56.1 -3.81 Duoi
## 5 LangSon 56.4 -3.48 Duoi
## 6 DienBien 56.6 -3.28 Duoi

Vẽ thêm nữa
library(ggpubr)
library(rlang)
library(tibble)
ggbarplot(
dlieu1,x="Tinh", y="plPCI",
fill="ploai",
color="white",
palette = "jco",
sort.by.groups = FALSE,
x.text.angle = 90,
sort.val = "asc",
size=0.1,
width=0.8,
rotate = TRUE,
position = position_stack(),
ggtheme = theme_minimal()
) +
labs(x=NULL, y=NULL)+ theme(legend.position = "none") + ylim(-5.5,8.5)+
theme(axis.text.x=element_text(size=11,color="#002feb"))+
theme(axis.text.y=element_text(size=11,color="#002feb"))
## Warning: Removed 1 rows containing missing values (position_stack).

Vẽ thanh kẹo
ggdotchart(dlieu1, x = "Tinh", y = "plPCI",
color = "ploai", # Color by groups
palette = c("#00AFBB", "#E7B800"), # Custom color palette
sorting = "ascending", # Sort value in descending order
add = "segments", # Add segments from y = 0 to dots
add.params = list(color = "lightgray", size = 2), # Change segment color and size
group = "ploai", # Order by groups
dot.size = 9, # Large dot size
label = round(dlieu1$tbPCI,1), # Add mpg values as dot labels
font.label = list(color = "white", size = 7,face="bold",
vjust = 0.5), # Adjust label parameters
ggtheme = theme_pubr() # ggplot2 theme
)+
geom_hline(yintercept = 0, linetype = 2, color = "lightgray")+
coord_flip() + labs(x=NULL, y=NULL)

Biểu đồ thanh ngang
ggdotchart(dlieu1, x = "Tinh", y = "tbPCI",
color = "ploai", # Color by groups
palette = c( "#ff8f03","#154360"), # Custom color palette
sorting = "descending", # Sort value in descending order
rotate = TRUE, # Rotate vertically
dot.size = 9,
label = round(dlieu1$tbPCI,1),
font.label = list(color = "white", size = 8,face = "bold",vjust = 0.5), #Large dot size
y.text.col = TRUE, # Color y text by groups
ggtheme = theme_pubr() # ggplot2 theme
)+
theme_cleveland()+ # Add dashed grids
labs(x=NULL, y=NULL) + theme(legend.position = "none")
## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.

Đồ thị GDP
dlieu2 <-dulieu %>% group_by(Tinh)%>%summarise(tbGDP = mean(GDPHH)) %>%mutate(plGDP = tbGDP-mean(tbGDP)) %>% mutate(ploai = ifelse(plGDP > 0,"Tren","Duoi")) %>% arrange(plGDP) %>% mutate(tbGDP2 = tbGDP/1000)
## `summarise()` ungrouping output (override with `.groups` argument)
head(dlieu2)
## # A tibble: 6 x 5
## Tinh tbGDP plGDP ploai tbGDP2
## <chr> <dbl> <dbl> <chr> <dbl>
## 1 BacKan -3867. -77829. Duoi -3.87
## 2 LangSon 5314. -68648. Duoi 5.31
## 3 SonLa 9131. -64831. Duoi 9.13
## 4 NinhThuan 12173. -61788. Duoi 12.2
## 5 QuangTri 12716. -61246. Duoi 12.7
## 6 DienBien 12886. -61076. Duoi 12.9
ggdotchart(dlieu2,x="Tinh", y="tbGDP2",
color="ploai",
palette =c( "#ff8f03","#154360"),
sorting="descending",
rotate=TRUE,
dot.size=9,
label=round(dlieu2$tbGDP2,0),
font.label=list(color="white", size=8, face="bold", vjust=0.5),
y.text.col=TRUE,
ggtheme=theme_pubr(),
)+ theme_cleveland()+
labs(x=NULL, y=NULL) + theme(legend.position = "none")
## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.
