Colors for two geom_point () in ggplot2 when using aes_string

I want to create a graph from two series “Pos” and “Neg” (y values) from a data frame. The x value is in the Medium column. I want the series to have a different color.

A stackoverflow search gave me a similar question: change the color for two geom_point () in ggplot2 , but I want to use aes_string to avoid notes when checking the package.

I get it to work using ice and “automatic” colors, as in the first example below. However, I cannot figure out how to create the same plot using aes_string and still allow ggplot colors. I feel it should just be ...

Playable example:

exData <- data.frame(Marker = rep("TH01", 10),
                 Mean = seq(1:10),
                 Neg = -1*runif(10,0.1,1),
                 Pos = runif(10,0.1,1))

# Produce the correct plot, with 'automatic' colours.
gp <- ggplot(exData, aes_string(x="Mean"),
             shape=val_shape, alpha=val_alpha)
gp <- gp + geom_point(aes(y=Pos, colour="Max"))
gp <- gp + geom_point(aes(y=Neg, colour="Min"))
gp <- gp + scale_colour_discrete(name = "Legend")
print(gp)

# Produce the correct plot, but not with 'automatic' colours.
gp <- ggplot(exData, aes_string(x="Mean"),
             shape=val_shape, alpha=val_alpha)
gp <- gp + geom_point(aes_string(y="Pos"), colour=1)
gp <- gp + geom_point(aes_string(y="Neg"), colour=2)
gp <- gp + scale_colour_discrete(name = "Legend")
print(gp)
+4
2

ggplot2. "" :

library(reshape2)
exData.m <- melt(exData, id.vars=c("Marker", "Mean"))

ggplot(exData.m, aes(x=Mean, y=value, color=variable)) + geom_point()

Result of plot

, (x, y, color, shape, alpha,...) , . reshape2.

+3

, ggplot ( "" "" ) . , , R. , "" , .

( ). ggplot R, :

y <- 1:6
barplot(y,col=y)

aes_string(...), , @krlmlr.

0

All Articles