I’m trying to create a barplot with ggplot2. However, I’m having a peculiar issue that I can’t figure out. Any suggestions would be greatly appreciated.
The issue is that Var1 150 corresponds to the highest Freq value, as shown in the data (‘sorted_data’) below. However, the plot’s maximum point occurred much before 150. There is a scaling issue on the x-axis. Please provide guidance on how to resolve this issue.
ggplot(sorted_data, aes(x = as.numeric(Var1), y = Freq)) +
geom_bar(stat = "identity") +
scale_y_continuous( labels = unit_format(unit = "K", scale = 1e-3))
ggplot(frag.freq, aes(x =as.numeric(Var1), y = Freq)) +
geom_bar(stat = "identity") +
labs( x = "Fragment Length (bp)", y = "Frequency") +
xlim(25, 215) +
scale_y_continuous(labels = unit_format(unit = "K", scale = 1e-3))
this is my data set
sorted_data
Var1 Freq
25 25 4885
26 26 5223
27 27 5003
28 28 4995
29 29 4757
30 30 8047
31 31 7808
32 32 7464
33 33 7218
34 34 6787
35 35 7601
36 36 7511
37 37 7487
38 38 6803
39 39 6930
40 40 7200
41 41 6941
42 42 6925
43 43 6746
44 44 6635
45 45 7241
46 46 6689
47 47 6930
48 48 6984
49 49 7066
50 50 6817
51 51 6811
52 52 6635
53 53 6911
54 54 7059
55 55 6980
56 56 7333
57 57 7278
58 58 7122
59 59 7356
60 60 7077
61 61 7082
62 62 7089
63 63 7121
64 64 7159
65 65 7192
66 66 7371
67 67 7046
68 68 7509
69 69 7579
70 70 7496
71 71 7386
72 72 7540
73 73 7574
74 74 7787
75 75 7774
76 76 7799
77 77 7935
78 78 8294
79 79 8584
80 80 8769
81 81 8495
82 82 8577
83 83 8622
84 84 8992
85 85 8725
86 86 8911
87 87 9091
88 88 9151
89 89 9719
90 90 9758
91 91 10206
92 92 10282
93 93 10160
94 94 10369
95 95 10528
96 96 10711
97 97 10563
98 98 11248
99 99 12412
100 100 12794
101 101 12250
102 102 12599
103 103 12552
104 104 12349
105 105 12411
106 106 12375
107 107 13035
108 108 13705
109 109 13977
110 110 15056
111 111 14409
112 112 14686
113 113 14606
114 114 14518
115 115 15098
116 116 14990
117 117 15473
118 118 15725
119 119 17279
120 120 18648
121 121 19432
122 122 19931
123 123 19702
124 124 19053
125 125 18977
126 126 19010
127 127 19148
128 128 20159
129 129 21479
130 130 24099
131 131 26113
132 132 29668
133 133 32378
134 134 33078
135 135 32233
136 136 30291
137 137 32006
138 138 35599
139 139 43274
140 140 55341
141 141 62397
142 142 66397
143 143 74419
144 144 91330
145 145 138581
146 146 239763
147 147 627943
148 148 1777552
149 149 4663749
150 150 9642891
151 151 131652
152 152 36695
153 153 18855
154 154 16145
155 155 7646
156 156 5060
157 157 3210
158 158 3827
159 159 2519
160 160 2884
161 161 1680
162 162 1945
163 163 1006
164 164 1206
165 165 1305
166 166 883
167 167 481
168 168 564
169 169 466
170 170 600
171 171 330
172 172 430
173 173 417
174 174 328
175 175 498
176 176 483
177 177 122
178 178 132
179 179 101
180 180 119
181 181 68
182 182 64
183 183 52
184 184 44
185 185 54
186 186 36
187 187 28
188 188 16
189 189 29
190 190 23
191 191 16
192 192 12
193 193 16
194 194 12
195 195 10
196 196 12
197 197 8
198 198 20
199 199 15
200 200 6
201 201 6
202 202 16
203 203 5
204 204 6
205 205 3
206 206 4
207 207 1
208 208 1
209 209 2
210 210 3
213 213 2
215 215 2