ggplot2 not working like I would like - r

I try to plot this visual with ggplot2:
ggplot(Trump_df, aes(x=freq.dif, y=Spacing)) +
geom_text(aes(size=TrumpT.txt, label=row.names(Trump_df),
colour=freq.dif), alpha=0.7, family="Arial") +
geom_text(data=Kasich_df, aes(x=freq.dif, y=Spacing,
label=row.names(Kasich_df), size=KasichT.txt, color=freq.dif),
alpha=0.7, family="Arial") +
geom_text(data=both_df, aes(x=freq.dif, y=Spacing,
label=row.names(both_df), size=TrumpT.txt, color=freq.dif),
alpha=0.7, family="Arial") +
scale_size(range=c(3,11)) +
scale_colour_gradient(low="red3", high="blue3", guide="none") +
scale_x_continuous(breaks=c(min(Kasich_df$freq.dif), 0, max(Trump_df$freq.dif)),
labels=c("Twitted More by Kasich","Twitted Equally","Twitted More by Trump")) +
scale_y_continuous(breaks=c(0), labels=c("")) +
labs(title="Conway's Word Cloud, Tweets (Trump -vs- Kasich)", x="", y="", size="Word Frequency") +
theme_bw() +
theme(panel.grid.major.y = element_line(),
panel.grid.minor.x = element_line(),
plot.title = element_text(family="Arial", size=18)
But get a plot with the axis labels stacked:
Here are my data frames:
dput(df)
>dput(df)
structure(list(TrumpT.txt = c(25, 34, 8, 3, 11, 4, 3, 4, 4, 16,
4, 8, 21, 16, 3, 21, 3, 10, 9, 11, 4, 6, 3, 4, 3, 6, 4, 3, 5,
55), KasichT.txt = c(6, 5, 3, 4, 3, 4, 6, 3, 4, 7, 29, 3, 3,
5, 4, 4, 3, 6, 22, 3, 3, 4, 3, 3, 3, 6, 5, 4, 6, 4), freq.dif = c(19,
29, 5, -1, 8, 0, -3, 1, 0, 9, -25, 5, 18, 11, -1, 17, 0, 4, -13,
8, 1, 2, 0, 1, 0, 0, -1, -1, -1, 51)), .Names = c("TrumpT.txt",
"KasichT.txt", "freq.dif"), row.names = c("america", "amp", "back",
"best", "can", "candidate", "check", "day", "done", "gopdebate",
"john", "join", "just", "make", "nation", "new", "next", "now",
"ohio", "one", "see", "state", "talk", "tax", "thanks", "time",
"today", "voting", "watch", "will"), class = "data.frame")
dput(df$freq.dif)
>dput(df$freq.dif)
c(19, 29, 5, -1, 8, 0, -3, 1, 0, 9, -25, 5, 18, 11, -1, 17, 0,
4, -13, 8, 1, 2, 0, 1, 0, 0, -1, -1, -1, 51)
dput(Trump_df)
>dput(Trump_df)
structure(list(TrumpT.txt = c(3, 3, 4, 3, 9, 4, 3, 5), KasichT.txt = c(4,
6, 29, 4, 22, 5, 4, 6), freq.dif = c(-1, -3, -25, -1, -13, -1,
-1, -1), Spacing = c(-0.4, 0.0249155652709305, -0.184168514423072,
-0.2, 0.0361329583451152, 0, 0.2, 0.4)), .Names = c("TrumpT.txt",
"KasichT.txt", "freq.dif", "Spacing"), row.names = c("best",
"check", "john", "nation", "ohio", "today", "voting", "watch"
), class = "data.frame")
dput(Kasich_df)
>dput(Kasich_df)
structure(list(TrumpT.txt = c(25, 34, 8, 11, 4, 16, 8, 21, 16,
21, 10, 11, 4, 6, 4, 55), KasichT.txt = c(6, 5, 3, 3, 3, 7, 3,
3, 5, 4, 6, 3, 3, 4, 3, 4), freq.dif = c(19, 29, 5, 8, 1, 9,
5, 18, 11, 17, 4, 8, 1, 2, 1, 51), Spacing = c(-0.171893353201449,
0.113299035839736, -0.5, -0.5, -0.333333333333333, 0.0629540653899312,
0.5, -0.161544232908636, 0.166435130592436, 0.193869082257152,
0.0795861765742302, 0.5, 0, -0.139369543548673, 0.333333333333333,
0.117351376824081)), .Names = c("TrumpT.txt", "KasichT.txt",
"freq.dif", "Spacing"), row.names = c("america", "amp", "back",
"can", "day", "gopdebate", "join", "just", "make", "new", "now",
"one", "see", "state", "tax", "will"), class = "data.frame")
dput(both_df)
>dput(both_df)
structure(list(TrumpT.txt = c(4, 4, 3, 3, 3, 6), KasichT.txt = c(4,
4, 3, 3, 3, 6), freq.dif = c(0, 0, 0, 0, 0, 0), Spacing = c(-0.833333333333333,
-0.5, -0.166666666666667, 0.166666666666667, 0.5, 0.833333333333333)), .Names = c("TrumpT.txt", "KasichT.txt", "freq.dif", "Spacing"),
row.names = c("candidate", "done", "next", "talk", "thanks",
"time"), class = "data.frame")
I would like to have "Twitted More by Kasich" on the far left, "Twitted Equally" in the middle, and "Twitted More by Trump" on the far right. I have tried messing with the scale, but what I'm doing doesn't seem to work. I'd appreciate any help.

Related

geom_bar(), Y-axis goes way above data value

I am trying to visualize a data frame from a survey. I'm currently trying to plot a barplot with geom_bar(), that takes in "Life Satisfaction" as the y-axis, and "Family Values" as the x-axis. Note that the survey answer for Life Satisfaction is 1(very unsatisfied) to 10(very satisfied).
But for some reason when I try to plot this barplot, the y-axis goes way above 10, and I don't understand why.
This is my code:
df1 %>%
filter(df1$B_COUNTRY_ALPHA == "PAK") %>%
drop_na(Q49) %>%
ggplot(aes(x = Q1, y = Q49, fill = B_COUNTRY_ALPHA)) +
geom_bar(stat = "identity") +
labs(x = "Family Value",
y = "Life Satisfaction")
This is the graph that I get when I run it:
This is the first 20 rows of data that I want to work with:
On a side note: I was thinking of finding the mean of the Life Satisfaction data and maybe that will make the plot make sense but I am not sure how to do that
#GregorThomas I followed your instructions and I got this.
structure(list(B_COUNTRY_ALPHA = c("PAK", "PAK", "PAK", "PAK",
"PAK", "PAK", "PAK", "PAK", "PAK", "PAK", "PAK", "PAK", "PAK",
"PAK", "PAK", "PAK", "PAK", "PAK", "PAK", "PAK"), Q49 = c(7,
10, 10, 5, 1, 6, 6, 10, 10, 10, 4, 4, 8, 10, 10, 10, 10, 9, 10,
8), Q1 = c(1, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1), Q2 = c(1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1,
4, 1, 2, 2, 2), Q3 = c(2, 2, 1, 1, 3, 1, 2, 2, 2, NA, 2, 4, 1,
1, 2, 2, 4, 2, 4, 2), Q4 = c(3, 4, 2, 4, 2, 3, 4, 2, 1, 4, 4,
4, 4, 1, 3, 4, 3, 4, 4, 2), Q5 = c(1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 2, 1, 1, 1, 4, 1, 1, 4), Q6 = c(1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4), Q57 = c(2, 2, 2, 1, 1,
1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 1), Q106 = c(7, 5,
10, 4, 10, 7, 1, 10, 10, 10, 1, 10, 1, 10, 10, 10, 9, 4, 10,
6), Q107 = c(7, 6, 5, 5, 10, 3, 1, 10, 10, NA, 1, 1, 1, 10, 3,
10, 10, 8, 10, 4), Q108 = c(7, 9, 1, 4, 1, 1, 10, 10, 5, 10,
10, 10, 1, 10, 10, 10, 10, 10, 1, 3), Q109 = c(6, 4, 1, 4, 1,
1, 1, 10, 10, 1, 6, 2, 10, 5, 10, 1, 10, 9, 1, 4), Q110 = c(6,
3, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 10, 1, 10, 3, 1, 3), Q112 =
c(8,
8, 10, 6, 10, 5, 10, 10, 10, 10, NA, 10, 10, 10, 10, 10, 10,
10, 10, 7), Q163 = c(6, 2, 10, 7, 9, 10, 10, 10, 10, NA, 10,
10, 6, 10, 3, NA, 8, 7, NA, 9), Q164 = c(4, 9, 10, 8, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, NA, 8, 10, 10, 10), Q222 = c(2,
1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 4, NA, 1, NA, 2, 3, NA, 3),
Q260 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 0, 1), Q262 = c(33, 21, 60, 18, 60, 50, 45, 29, 62,
46, 35, 40, 30, NA, 45, NA, 30, 50, 36, 34), Q273 = c(1,
6, 1, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
Q275 = c(0, 2, 3, 3, 3, 2, 3, 2, 4, 0, 0, 0, 1, NA, 3, NA,
1, 1, 0, 1), Q281 = c(8, 0, 3, 0, 10, 3, 4, 6, 3, 8, 4, 4,
4, 0, 5, 0, 0, 0, 9, 0)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -20L))
Here's a couple ideas using your sample data:
Use a dodged bar plot:
sample_data %>%
ggplot(aes(x = factor(Q1), fill = factor(Q49))) +
geom_bar(position = position_dodge(preserve = 'single')) +
labs(x = "Family Value",
y = "Count of Responses",
fill = "Life Satisfaction")
Use facets:
sample_data %>%
ggplot(aes(x = factor(Q49), fill = factor(Q49))) +
geom_bar() +
labs(x = "Life Satisfaction",
y = "Count of Responses",
fill = "Life Satisfaction") +
facet_wrap(vars(paste("Family Value", Q1)))
Use a heat map:
sample_data %>%
ggplot(aes(x = factor(Q1),y = factor(Q49))) +
geom_bin2d() +
coord_fixed() +
labs(y = "Life Satisfaction", x = "Family Value")

How to convert igraph file in row/colums?

I would like to pass the information I have to a normal list of axes with nodes but I don't know how to do it. The raw data with "deput" would look like this. If someone knows how to convert this list into something easier to use I would appreciate it.I can visualise the graph with "plot" but to edit it I need to have more precise information.
library(igraph)
dput (net2$graph_pajek)
structure(list(30, FALSE, c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 6, 7, 13, 13,
14, 15, 16, 18, 20, 20, 21, 27, 27, 27, 27, 29, 2, 2, 2, 2, 2,
2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5,
6, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 12, 12, 12,
13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 18, 18, 18, 19, 20, 20,
21, 21, 23, 24, 25, 26, 27, 27, 27, 29, 3, 3, 3, 3, 3, 3, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
5, 5, 5, 5, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 10,
10, 10, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 15), list(c(1, 0, 1), structure(list(), .Names = character(0)),
list(name = c("A", "B", "C",
"D", "E", "F", "G", "H",
"I", "J", "K",
"L", "M", "N",
"O", "P", "Q", "R",
"S", "T", "U",
"V", "W", "X", "Y", "Z",
"AB", "AC", "AD", "AE"
), deg = c(248, 532, 855, 574, 1761, 261, 229, 216, 554,
628, 774, 223, 502, 295, 266, 910, 227, 312, 364, 260, 294,
741, 227, 471, 392, 376, 292, 295, 212, 287), size = c(2.,
6, 9, 6, 20,
2, 2, 2, 6,
7, 8, 2, 7,
3, 3, 10, 2,
3, 4, 2, 3.,
8, 2, 5, 4,
4, 3, 3, 2,
3), label.cex = c(0.7, 0.7, 0.7, 0.7, 0.7, 0.7,
0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7,
0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7
), id = c("A", "B", "C",
"D", "E", "F", "G", "H",
"I", "J", "K",
"L", "M", "N",
"O", "P", "Q", "R",
"S", "T", "U",
"V", "W", "X", "Y", "Z",
"AB", "AC", "AD", "AE"
)), list(num = c(4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 3, 3, 3,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 1, 1, 2,
2, 1, 1, 1, 1, 2, 2, 1, 4, 4, 4, 4, 1, 7, 7, 7, 7, 7, 7,
7, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 12, 12, 1, 2, 2, 1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 2,
2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 1, 2,
2, 2, 2, 1, 1, 1, 1, 3, 3, 3, 1, 6, 6, 6, 6, 6, 6, 40, 40,
40, 40, 40, 40, 40, 40, 40), weight = c(4, 4, 4, 4,
7, 7, 7, 7, 7, 7, 7, 3, 3, 3, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 3, 3, 3, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 4,
4, 4, 4, 1, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 12, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 2, 2, 1, 2, 2,
3, 3, 3, 5, 5, 5, 5, 5, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 1, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 3, 3, 3,
1, 6, 6, 6, 6, 6, 6, 40, 40, 40, 40, 40, 40, 40, 40, 40,
40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
40, 7, 7, 7, 7, 7, 7, 7, 1, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7,
4, 4, 4, 4, 4, 4, 4, 4, 1, 18, 18))), <environment>), class = "igraph")
Are you looking for something like get.data.frame
> get.data.frame(net)
from to weight
1 A B 0.63502922
2 B C 0.79410173
3 C D 0.90802625
4 D E 0.09408188
5 E F 0.16450634
6 F G 0.75931882
7 G H 0.30409658
8 H I 0.23990324
9 I J 0.84762277
10 A J 0.88657718
data
Since I cannot reproduce the example in your post, I created a dummy example net like below
net <- make_ring(10) %>%
set_vertex_attr(name = "name", value = LETTERS[1:vcount(.)]) %>%
set_edge_attr(name = "weight", value = runif(ecount(.)))
To clarify a couple things:
The igraph file is not a plot per se, but a graph structure (as in, nodes and edges).
igraph has functions for plotting graphs, but there is no single and standard way of plotting a graph - instead, different algorithms can be used to determine visually-ideal ways of displaying them, and these algorithms oftentimes rely on random initializations.
The outputs from the plotting functions of igraph are only relevant in terms of R base plot drawing logic, AFAIK they don't use an intermediate format with coordinates handled in a user-comprehensible structure. You can nevertheless manage lots of aspects of how they are drawn - see ?igraph::igraph.plotting.

How to create ggplot graphs with the three groups into one plot?

My codes are:
ggplot(data=df2, aes(x=stress, fill=as.factor(JP_Gender))) + geom_density(alpha=.3)
ggplot(data=df1, aes(x=CGstress)) + geom_density(alpha=.3)
My dataset 1:
structure(list(CGstress = c(4, 1, 10, 8, 9.5, 5, 5, 6, 6, 6,
7, 3, 4.5, 8, 9, 1, 5, 1, 5.5, 4, 1, 7, 9, 8, 3, NA, 10, 9, 5,
3, NA, 10, 6, NA, 10, 7)), row.names = c(NA, -36L), class = c("tbl_df",
"tbl", "data.frame"))
My dataset 2:
structure(list(stress = c(7, 2, 5, 6, 7, 1, 6, 10, 9, 10, 10,
10, 10, 8, 9, 4, 7, 6, 4, 9, 4, 8, 3.5, 7, 6, 6, 1, 7, 9, 8,
10, 6, 3, 1, 1, 1, 9, 6, 4), JP_Gender = structure(c(1, 2, 1,
2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1), label = "What is your gender?", format.stata = "%12.0g", labels = c(Male = 1,
Female = 2, Transgender = 3, Other = 4), class = c("haven_labelled",
"vctrs_vctr", "double"))), row.names = c(NA, -39L), class = c("tbl_df",
"tbl", "data.frame"))
Above codes give me 2 graphs. How to combine 2 graphs into one plot? And how to label the legends?
You can try combining the two datasets and then plot :
library(dplyr)
library(ggplot2)
df1 %>%
mutate(id = 3) %>%
rename(stress = CGstress) %>%
bind_rows(df2 %>%
mutate(id = as.integer(JP_Gender)) %>%
select(stress, id)) %>%
mutate(id = factor(id)) %>%
ggplot(aes(x=stress, fill=factor(id))) + geom_density(alpha=.3)

How to fix invalid vertex id error in tidygraph?

Data
network_data <- list(nodes = structure(list(id = c(0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14), label = c("2892056", "2894543", "2894544",
"2894545", "2894546", "2894547", "2894548", "2894549", "2894550",
"2894551", "2894552", "2894553", "2894554", "2894555", "2894556"
)), row.names = c(NA, -15L), class = "data.frame"), links = structure(list(
from = c(3, 5, 7, 13, 13, 7, 3, 5, 0, 0, 5, 2, 7, 6, 13,
11, 0, 3, 2, 7, 13, 3, 0, 0, 5, 3, 13, 4, 0, 14, 13, 7, 2,
3, 5, 0, 12), to = c(0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3,
3, 3, 3, 4, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 11, 12, 12,
12, 13, 13, 13, 13, 13, 14), weight = c(1, 2, 2, 1, 2, 1,
1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1, 1,
2, 1, 2, 1, 1, 2, 2, 2, 1, 2, 1, 1)), row.names = c(NA, -37L
), class = "data.frame"))
I have this list of nodes and links for building a network. Rather than plotting the network, I want to get the network characteristics such as isolates, reciprocity, etc.
Here's the rest of the code that I'm using to obtain these characteristics:
network_data$nodes <- network_data$nodes %>% select(id, label)
network_data$links <- network_data$links %>% rename(from = source, to = target)
print(network_data$nodes)
print(network_data$links)
SNA <- tidygraph::tbl_graph(
nodes = network_data$nodes,
edges = network_data$links,
directed = T
)
The last line is where it errors out.
Error in (function (edges, n = max(edges), directed = TRUE) :
At structure_generators.c:86 : Invalid (negative) vertex id, Invalid vertex id
I googled the issue and seems like it's pretty prevalent, but none of the methods suggested worked for me. What's different in my data that it's still generating the error, and how can I resolve this error?

Select Input in ggplot Shiny dashboard - Error: object not found

I am trying to create ggplot output using R Markdown Shiny Document. I need it to plot data based on the selection in a dropdown menu. My code:
df<- data.frame(df,out)
renderRpivotTable({
rpivotTable(data = df, rows = c("organisationunitname","X2"), cols = "X1", vals = "value",
aggregatorName = "List Unique Values",inclusions = list(organisationunitname=list("All OUs")),
rendererName = "Lab Table", width = "100%", height = "500px") })
orgunit <- c("Cy3L", "Yieu", "j9ao", "H3LY", "U3nd",
"qU1l", "jXVh", "dXHb", "tCq8", "Blee", "5jra", "qO2V", "Qa9J",
"2XIy", "MJpY", "tNKa", "UorU", "7pZt", "Mxsz", "WCkd", "BiDp",
"Zw8w", "0J7c", "9YtI", "TAkB", "py3Q", "RdQt", "Yhv1", "PB0X",
"H3L4", "INY7", "DpTW", "3zXP", "OqpO", "tiZU", "5wnz")
inputPanel(selectInput("OU", label = "Select OU:", choices = orgunit, selected = "All OUs"))
renderPlot({
df1=reactive({return(df[organisationunitname %in% as.character(input$OU)])})
ggplot(data = df1(),aes(x=X1,y=value))+geom_bar(stat = "identity")+facet_grid(X2~.)
})
It gives me this error: object 'organisationunitname' not found
Error Message
My data:
structure(list(country = c("Cy3L", "Yieu", "j9ao", "H3LY", "U3nd",
"qU1l", "jXVh", "dXHb", "tCq8", "Blee", "5jra", "qO2V", "Qa9J",
"2XIy", "MJpY", "tNKa", "UorU", "7pZt", "Mxsz", "WCkd", "BiDp",
"Zw8w", "0J7c", "9YtI", "TAkB", "py3Q", "RdQt", "Yhv1", "PB0X",
"H3L4", "INY7", "DpTW", "3zXP", "OqpO", "tiZU", "5wnz"), cd4_perform_result = structure(c(24L,
6L, 7L, 1L, 1L, 1L, 5L, 3L, 2L, 1L, 10L, 1L, 2L, 8L, 1L, 2L,
17L, 1L, 1L, 23L, 12L, 1L, 14L, 11L, 18L, 1L, 21L, 16L, 1L, 22L,
19L, 4L, 1L, 15L, 20L, 9L), .Label = c("0", "1", "11", "125",
"130", "14", "15", "194", "24", "261", "27", "31", "3442", "370",
"4", "5", "51", "567", "577", "73", "76", "79", "796", "9", "end"
), class = "factor"), cd4_participate_result = c(1, 8, 8, 1,
1, 1, 5, 3, 2, 1, 7, 1, 2, 9, 1, 2, 17, 1, 1, 18, 12, 1, 4, 15,
14, 1, 20, 16, 1, 21, 10, 6, 1, 19, 13, 3), cd4_pass_result = c(1,
4, 19, 1, 1, 1, 5, 3, 2, 1, 21, 1, 2, 20, 1, 2, 13, 1, 1, 14,
6, 1, 11, 12, 10, 1, 18, 2, 1, 16, 7, 17, 1, 15, 9, 3), eid_perform_result = c(2,
1, 7, 1, 1, 1, 1, 9, 1, 1, 8, 1, 2, 3, 5, 2, 5, 1, 1, 10, 5,
1, 4, 2, 11, 1, 5, 1, 1, 5, 9, 2, 1, 1, 9, 5), eid_participate_result = c(2,
1, 5, 1, 1, 1, 1, 8, 1, 1, 7, 1, 2, 10, 5, 2, 5, 1, 1, 4, 2,
1, 10, 2, 9, 1, 5, 1, 1, 5, 7, 2, 1, 1, 6, 5), eid_pass_result = c(2,
1, 5, 1, 1, 1, 1, 7, 1, 1, 6, 1, 2, 10, 1, 2, 5, 1, 1, 4, 2,
1, 9, 2, 8, 1, 5, 1, 1, 5, 6, 2, 1, 1, 5, 5), vl_perform_result = c(2,
1, 3, 1, 1, 1, 1, 9, 1, 1, 10, 1, 2, 11, 5, 2, 5, 1, 1, 6, 5,
1, 8, 7, 6, 1, 12, 1, 1, 5, 9, 2, 1, 1, 8, 5), vl_participate_result = c(2,
1, 7, 1, 1, 1, 1, 7, 1, 1, 8, 1, 2, 8, 4, 2, 4, 1, 1, 5, 2, 1,
4, 6, 3, 1, 9, 1, 1, 4, 7, 2, 1, 1, 6, 1), vl_pass_result = c(2,
1, 7, 1, 1, 1, 1, 7, 1, 1, 9, 1, 2, 8, 1, 2, 5, 1, 1, 4, 2, 1,
2, 6, 3, 1, 11, 1, 1, 5, 7, 2, 1, 1, 5, 1), hiv_perform_result = c(19,
29, 14, 1, 1, 1, 26, 21, 10, 1, 6, 11, 9, 7, 20, 27, 8, 15, 1,
28, 12, 1, 25, 18, 24, 1, 22, 5, 1, 23, 17, 16, 1, 2, 3, 4),
hiv_participate_result = c(19, 28, 14, 1, 1, 1, 22, 20, 4,
1, 16, 9, 10, 3, 12, 27, 5, 1, 1, 21, 6, 1, 24, 18, 13, 1,
25, 8, 1, 23, 15, 17, 1, 2, 26, 7), hiv_pass_result = c(20,
28, 14, 1, 1, 1, 18, 22, 7, 1, 17, 27, 11, 2, 24, 26, 10,
1, 1, 15, 4, 1, 21, 19, 12, 1, 23, 8, 1, 16, 13, 9, 1, 3,
25, 6), tbafb_perform_result = c(9, 1, 8, 1, 1, 1, 1, 7,
1, 1, 6, 1, 21, 5, 1, 2, 12, 1, 1, 15, 13, 1, 17, 11, 20,
1, 10, 1, 1, 14, 16, 4, 1, 18, 3, 1), tbafb_participate_result = c(1,
1, 18, 1, 1, 1, 1, 5, 1, 1, 12, 1, 19, 11, 1, 2, 6, 1, 1,
13, 7, 1, 10, 9, 14, 1, 8, 1, 1, 16, 15, 4, 1, 18, 3, 1),
tbafb_pass_result = c(1, 1, 19, 1, 1, 1, 1, 6, 1, 1, 13,
1, 20, 11, 1, 2, 4, 1, 1, 15, 5, 1, 7, 10, 12, 1, 8, 1, 1,
16, 9, 3, 1, 14, 18, 1), tbculture_perform_result = c(3,
1, 2, 1, 1, 1, 1, 1, 1, 1, 6, 1, 3, 8, 1, 2, 2, 1, 1, 7,
3, 1, 5, 4, 7, 1, 5, 1, 1, 3, 6, 6, 1, 3, 3, 1), tbculture_participate_result = c(1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 6, 1, 4, 9, 1, 2, 2, 1, 1, 8,
2, 1, 7, 5, 7, 1, 1, 1, 1, 4, 4, 6, 1, 4, 4, 1), tbculture_pass_result = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 8, 1, 2, 2, 1, 1, 9,
2, 1, 7, 5, 6, 1, 1, 1, 1, 4, 4, 7, 1, 4, 4, 1), tbxpert_perform_result = c(1,
1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 17, 1, 8, 3, 1, 1, 5,
9, 1, 16, 7, 13, 1, 4, 1, 1, 12, 11, 1, 1, 6, 14, 10), tbxpert_participate_result = c(1,
1, 5, 1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 4, 1, 12, 3, 1, 1, 2,
7, 1, 17, 9, 11, 1, 1, 1, 1, 14, 10, 1, 1, 6, 8, 13), tbxpert_pass_result = c(1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 13, 1, 1, 4, 1, 9, 3, 1, 1, 15,
6, 1, 14, 8, 8, 1, 1, 1, 1, 12, 6, 1, 1, 5, 7, 10)), .Names = c("organisationunitname",
"cd4_perform_result", "cd4_participate_result", "cd4_pass_result",
"eid_perform_result", "eid_participate_result", "eid_pass_result",
"vl_perform_result", "vl_participate_result", "vl_pass_result",
"hiv_perform_result", "hiv_participate_result", "hiv_pass_result",
"tbafb_perform_result", "tbafb_participate_result", "tbafb_pass_result",
"tbculture_perform_result", "tbculture_participate_result", "tbculture_pass_result",
"tbxpert_perform_result", "tbxpert_participate_result", "tbxpert_pass_result"
), row.names = c(NA, 36L), class = "data.frame")
I am not sure why it's not reading the "organisationunitname" column. Please help.
I think your error is this line:
df1=reactive({return(df[organisationunitname %in% as.character(input$OU)])})
Change it to:
df1=df[df$organisationunitname %in% as.character(input$OU),])
You also have the incorrect number of dimensions and reactive is not required here because the expression is already in a reactive function: renderPlot.

Resources