i have little problem ggplot barchart.
i wanted make barchart ggplot2 in order compare svolumes 4 stocks on period of few months.
i have 2 problems:
the first 1 y axis wrong. graph/data seems correct y axis don't "follow" thought contain scale... have "total" number of dataset svolumes, think here writing svolumes values. don't know how explain scale corresponding of data on graph 10,20,etc until highest sum of svolumes.
there code:
date=c(rep(data$date)) subject=c(rep(data$subject)) svolume=c(data$svolume) data=data.frame(date,subject,svolume) data=ddply(data, .(date),transform,pos=cumsum(as.numeric(svolume))-(0.5*(as.numeric(svolume)))) ggplot(data, aes(x=date, y=svolume))+ geom_bar(aes(fill=subject),stat="identity")+ geom_text(aes(label=svolume,y=pos),size=3) and there plot:

i helped question here
finally, how make same plot each months please? don't know how values per month in order have more readable barchart can't read here...
if have other ideas me glad take ideas , advices! maybe same line chart more readable...? or maybe same barchart each stocks ? (i don't know how values per stock either...)
i found how lines.... once again y axis wrong, , it's not readable....

thanks !! :)
try adding following line right before ggplot function. looks y-axis in character.
[edit] incorporate @user20650's comments, add as.character() first convert numeric.
data$svolume <- as.numeric(as.character(data$svolume)) to produce same plot each month, can add month variable first: data$month <- month(as.date(date)). add facet ggplot object.
ggplot(data, aes(x=date, y=svolume) + ... + facet_wrap(~ month) for example, bar chart code be:
data$svolume <- as.numeric(as.character(data$svolume)) data$month <- month(as.date(date)) ggplot(data, aes(x=date, y=svolume)) + geom_bar(aes(fill=subject),stat="identity") + geom_text(aes(label=svolume,y=pos),size=3) + facet_wrap(~ month) and line chart code be:
data$svolume <- as.numeric(as.character(data$svolume)) data$month <- month(as.date(date)) ggplot(data, aes(x=date, y=svolume, colour=subject)) + geom_line() + facet_wrap(~ month)
Comments
Post a Comment