facet wrap

123 views
Skip to first unread message

paulniyi

unread,
Jul 26, 2024, 11:35:47 AM7/26/24
to ggplot2
please how can I make a ggplot of facet wrap for this data

Antibiotics Year2016 Year2017 Year2018 Year2019 Year2020 Year2021 Year2022
GN 443 242 608 692 374 296 413
STR 6 8 3 4 6 3 10
CFX 410 132 426 731 578 396 372
CFZ 257 116 331 465 438 126 283
CTZ 252 74 321 388 341 244 245
CEF 0 3 5 1 13 1 159
CXT 0 0 0 0 6 256 314
CFP 0 0 22 22 188 264 235
OFX 162 109 212 229 238 178 262
CIP 104 48 117 102 127 102 139
LEV 0 0 6 2 43 93 93
CXC 329 184 552 289 39 0 0
AMP 12 3 6 3 41 11 28
AUG 337 133 336 508 392 423 470
AZT 0 0 0 0 1 22 51
ERY 431 211 691 672 179 96 149
NIT 3 2 2 5 4 2 2
TET 2 1 3 2 1 1 1
COT 0 0 0 0 2 1 1
IMP 0 0 0 2 22 75 102



avi.e...@gmail.com

unread,
Jul 26, 2024, 1:17:00 PM7/26/24
to paulniyi, ggplot2

Paul,

 

Facet_wrap() and a few relatives are the end of a process and you left out the rest of what you want.

 

You need to first have multiple lines of code that would make some kind of graph using ggplot(…) + geom_line(…) and so on first and then use facet_wrap(…), with appropriate arguments, to specify a formula that results in making multiple plots that vary depending on what you want.

 

In many cases, you would need to first change the format of your data such as condensing Year2016 through Year2022 into long format so that you have a field like “YEAR” and another like “VALUE” and then work on it.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ggplot2/d13cff0f-e97d-4c2e-b84f-eb6c900c76fen%40googlegroups.com.

Muhammad Zubair Ishaq

unread,
Sep 14, 2024, 10:13:18 AM9/14/24
to ggplot2
Here you can find 
Rotate ggplot2 Axis Labels in R: Improve Plot Readability
Learn Master ggplot2 axis label rotation in R for clearer visualizations. Learn to rotate x and y-axis labels to any angle and avoid overlaps
The theme() function and axis.text.x control
Think of the theme() function as your ggplot2 customization central. It lets you tweak all sorts of visual stuff, including tick labels and their positioning. Within theme(), the axis.text.x element specifically targets your x-axis labels. This is where the rotation magic happens!
Step-by-step code example
Let's use our iris scatterplot from earlier:
ggplot(df, aes(x = long_labels, y = response)) + geom_point() + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

Read more ggplot rotate axis labels
Reply all
Reply to author
Forward
0 new messages