How to go about stacked bar graph

Year PFCE GFCE GFCF Export of goods and services Import of goods and services
1950-51 9109 569 1169 736 711
1951-52 9994 597 1256 846 1038
1952-53 9971 618 1180 715 702
1953-54 10850 653 1166 644 652
1954-55 10098 681 1363 705 750
1955-56 10100 729 1646 757 839
1956-57 11913 804 2052 767 1174
1957-58 12084 940 2053 800 1304
1958-59 13718 1008 2058 719 1104
1959-60 14260 1062 2244 779 1010
1960-61 15409 1159 2549 787 1205
1961-62 16112 1288 2944 804 1113
1962-63 16969 1562 3206 837 1211
1963-64 18839 2007 3769 987 1362
1964-65 22179 2163 4380 1002 1529
1965-66 23411 2492 4855 938 1478
1966-67 27265 2731 5372 1330 2142
1967-68 32491 3054 6042 1517 2236
1968-69 32506 3344 6453 1608 1968
1969-70 35163 3748 7068 1628 1767
1970-71 37306 4189 7274 1771 1816
1971-72 40236 4848 8313 1838 2006
1972-73 44347 5157 9421 2225 2049
1973-74 53461 5653 10696 2830 3176
1974-75 64771 6859 13180 3835 4779
1975-76 66240 8085 15095 4812 5664
1976-77 68867 8979 16975 6139 5614
1977-78 79304 9580 19546 6640 6517

How do I plot a stacked bar graph with each stack containing all of the given columns(leaving the year of course ).
So basically against each year I need a stack of all of the given columns for that year.

You want to pivot your data into long format and then you'll be able to use this to create a column plot.

library(tidyr)
library(ggplot2)
data |>
  pivot_longer(cols = -"Year", names_to = "Category", values_to = "Count") |>
  ggplot(aes(x = Year, y = Count, fill = Category)) +
  geom_col()

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.