Reputation: 12550
I have a dataframe as such:
1 Pos like 77
2 Neg like 58
3 Pos make 44
4 Neg make 34
5 Pos movi 154
6 Neg movi 145
...
20 Neg will 45
I would like to produce a plot using the geom_text
layer in ggplot2.
I have used this code
q <- ggplot(my_data_set, aes(x=value, y=value, label=variable))
q <- q + geom_text()
q
which produced this plot:
Obviously, this is not an ideal plot.
I would like to produce a plot similar, except I would like to have the Positive class on the x-axis, and the Negative class on the y-axis.
UPDATE: Here is an example of something I am attempting to emulate:
I can't seem to figure out the correct way to give the arguments to the geom_line
layer.
What is the correct way to plot the value of the Positive arguments on the X-axis, and the value of the Negative arguments on the Y-axis, given the data frame I have?
Thanks for your attention.
Upvotes: 3
Views: 224
Reputation: 83215
This can also be easily done with reshape2
(with the same result as David Arenburg's answer):
df <- read.table(text = "id variable value
Pos like 77
Neg like 58
Pos make 44
Neg make 34
Pos movi 154
Neg movi 145", header = TRUE)
require(reshape2)
df2 <- dcast(df, variable ~ id, value.var="value")
library(ggplot2)
ggplot(df2, aes(x=Pos, y=Neg, label=variable)) +
geom_text()
which results in:
Upvotes: 1
Reputation: 92292
my_data_set <- read.table(text = "
id variable value
Pos like 77
Neg like 58
Pos make 44
Neg make 34
Pos movi 154
Neg movi 145", header = T)
library(data.table)
my_data_set <- as.data.frame(data.table(my_data_set)[, list(
Y = value[id == "Neg"],
X = value[id == "Pos"]),
by = variable])
library(ggplot2)
q <- ggplot(my_data_set, aes(x=X, y=Y, label=variable))
q <- q + geom_text()
q
Upvotes: 4