In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the ggplot2 Cartesian coordinate system x, y axis how to exchange the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this ggplot2 Cartesian coordinate system x, y axis exchange article will have something to gain, let's take a look.
Library ('ggplot2') library (' reshape2') A = c ("A", "B", "C", "D", "E") B = c (9014) dat = data.frame (A type, "sample1", "sample2") dat = melt (dat,variable.name= "Sample", value.name = "Num") head (dat) p = ggplot (dat, aes (x = type,y = Num) Fill = Sample) + geom_bar (stat = "identity", width= 0.6 position = position_dodge (width=0.8)) + scale_fill_manual (values = c ("red", "blue")) + labs (x = "", y = ", title =" test ") + geom_text (aes (label = dat$Num), position=position_dodge (width= 0.9), size = 5 Vjust =-0.25) + guides (fill = guide_legend (reverse = F)) + theme (plot.title = element_text (size= 25pint face = "bold", vjust = 0.5, hjust = 0.5), legend.title = element_blank (), legend.text = element_text (size= 18, face = "bold"), legend.position = 'right', legend.key.size=unit (0.8 camera cm') p=p+coord_flip () p
However, it can be seen that after the coordinate exchange, the original settings need to adjust the position of the text in the text layer, specifically adjust vjust and hjust. For example:
Library ('ggplot2') library (' reshape2') A = c ("A", "B", "C", "D", "E") B = c (9014) dat = data.frame (A type, "sample1", "sample2") dat = melt (dat,variable.name= "Sample", value.name = "Num") head (dat) p = ggplot (dat, aes (x = type,y = Num) Fill = Sample) + geom_bar (stat = "identity", width= 0.6 position = position_dodge (width=0.8)) + scale_fill_manual (values = c ("red", "blue")) + labs (x = "", y = ", title =" test ") + geom_text (aes (label = dat$Num), position=position_dodge (width= 0.9), size = 5Covjust = 0.5 Hjust=-0.25) + guides (fill = guide_legend (reverse = F)) + theme (plot.title = element_text (size= 25 bold = "bold", vjust = 0.5, hjust= 0.5), legend.title = element_blank (), legend.text = element_text (size= 18, face = "bold"), legend.position = 'right', legend.key.size=unit (0.8) 'cm')) p=p+coord_flip () p on "how the x and y axes of the ggplot2 Cartesian coordinate system are interchanged" ends here. Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to exchange the x and y axes of ggplot2 Cartesian coordinate system". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.