In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.