Wednesday, 15 May 2013

r - How the change line width in ggplot? -



r - How the change line width in ggplot? -

datalink: the info used

my code:

ccfsisims <- read.csv(file = "f:/purdue university/ra_position/phd_researchanddissert/phd_draft/gtap-cge/gtap_newaggdatabase/newfiles/gtap_consindex.csv", header=true, sep=",", na.string="na", dec=".", strip.white=true) ccfsirsts <- as.data.frame(ccfsisims) ccfsirsts[6:24] <- sapply(ccfsirsts[6:24],as.numeric) ccfsirsts <- droplevels(ccfsirsts) ccfsirsts <- transform(ccfsirsts,sres=factor(sres,levels=unique(sres))) library(ggplot2) #------------------------------------------------------------------------------------------ #### plot of nutrient security index kingdom of morocco , turkey sector #------------------------------------------------------------------------------------------ #_code_begin... datamortur <- melt(ccfsirsts[ccfsirsts$region %in% c("tur","mar"), ]) # selecting regions of involvement datamortur1 <- datamortur[datamortur$variable %in% c("pfsi2"), ] # selecting nutrient security index of involvement datamortur2 <- datamortur1[datamortur1$sector %in% c("wht","gro","vegtfrut","osd","othcrop","vegtoil","xprfood"), ] # selecting nutrient sectors of involvement datamortur3 <- subset(datamortur2, tradlib !="basedata") # eliminating "basedata" scenario results allfsi.f <- datamortur3 fsi.wht <- allfsi.f[allfsi.f$sector %in% c("wht"), ] figure29 <- ggplot(data=fsi.wht, aes(x=factor(sres),y=value,colour=factor(tradlib))) figure29 + geom_line(aes(group=factor(tradlib),size=2)) + facet_grid(regionsfull~., scales="free_y", labeller=reg_labeller) + scale_colour_brewer(type = "div") + theme(axis.text.x = element_text(colour = 'black', angle = 90, size = 13, hjust = 0.5, vjust = 0.5),axis.title.x=element_blank()) + ylab("fsi (%change)") + theme(axis.text.y = element_text(colour = 'black', size = 12), axis.title.y = element_text(size = 12, hjust = 0.5, vjust = 0.2)) + theme(strip.text.y = element_text(size = 11, hjust = 0.5, vjust = 0.5, face = 'bold'))

my result:

newresult aes(size=2):

my question: there way command line width more exactly avoid result in sec plot? particularly find document-unfriendly, , more publishing purposes include plot newly defined line width.

best, ismail

whilst @didzis has correct answer, expand on few points

aesthetics can set or mapped within ggplot call.

an aesthetic defined within aes(...) mapped data, , legend created.

an aesthetic may set single value, defining outside aes().

as far can tell, want set size single value, not map within phone call aes()

when phone call aes(size = 2) creates variable called `2` , uses create size, mapping constant value within phone call aes (thus appears in legend).

using size = 1 (and without reg_labeller perhaps defined somewhere in script)

figure29 + geom_line(aes(group=factor(tradlib)),size=1) + facet_grid(regionsfull~., scales="free_y") + scale_colour_brewer(type = "div") + theme(axis.text.x = element_text(colour = 'black', angle = 90, size = 13, hjust = 0.5, vjust = 0.5),axis.title.x=element_blank()) + ylab("fsi (%change)") + theme(axis.text.y = element_text(colour = 'black', size = 12), axis.title.y = element_text(size = 12, hjust = 0.5, vjust = 0.2)) + theme(strip.text.y = element_text(size = 11, hjust = 0.5, vjust = 0.5, face = 'bold'))

and size = 2

figure29 + geom_line(aes(group=factor(tradlib)),size=2) + facet_grid(regionsfull~., scales="free_y") + scale_colour_brewer(type = "div") + theme(axis.text.x = element_text(colour = 'black', angle = 90, size = 13, hjust = 0.5, vjust = 0.5),axis.title.x=element_blank()) + ylab("fsi (%change)") + theme(axis.text.y = element_text(colour = 'black', size = 12), axis.title.y = element_text(size = 12, hjust = 0.5, vjust = 0.2)) + theme(strip.text.y = element_text(size = 11, hjust = 0.5, vjust = 0.5, face = 'bold'))

you can define size work appropriately final image size , device type.

r ggplot2 line-plot

No comments:

Post a Comment