A few problems with your code.
Missing a close-paren after
nodes %>% filter(actor_ctr...)or
filter(nodes, actor_ctr...), not both.
nodesin the call to
ggplot. There are times when you can (and should) reference an external dataframe in ggplot layers, this is not one of them. Here’s what is actually being interpreted:
nodes %>% filter(actor_ctr %in% c(3,4,888)) %>% ggplot(data = ., mapping = nodes, aes(act_sm, pop_sm)) + geom_point(aes(x= act_sm, y= pop_sm, colour = actor_ctr), size=2)
.refers to the 8 rows of data after
nodesrefers to your frame before the pipeline started. While
.is not formally assigned to a variable, it is still the state of the data at that point in the pipe. Here, it’s 8 rows with all of the same columns, but it’s not hard to come up with examples where
origdatahave completely different shape and properties.
Further, because of the positional args there,
mapping=should certainly not be your
Your color aesthetic is based on a number, so
ggplot2is going to infer that it is continuous, whereas I believe it is in fact ordinal or categorical (discrete). This can often be fixed using
Let’s try to fix all of those:
nodes %>% filter(actor_ctr %in% c(3, 4, 888)) %>% ggplot(aes(act_sm, pop_sm)) + geom_point(aes(x = act_sm, y = pop_sm, colour = factor(actor_ctr)), size = 2)
CLICK HERE to find out more related problems solutions.