GoogleSearch
이 블로그 검색
gpplot2 examples
라벨:
Informatics
이메일로 전송BlogThis!Twitter에서 공유Facebook에서 공유
URL
- http://docs.ggplot2.org/0.9.3/theme.html
Color
- http://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette
- http://www.r-bloggers.com/r-using-rcolorbrewer-to-colour-your-figures-in-r/
- http://www.cookbook-r.com/Graphs/Colors_%28ggplot2%29/
- http://stackoverflow.com/questions/21322819/generating-a-consistent-dynamic-color-palette-in-ggplot-within-a-loop
Layout
- http://stackoverflow.com/questions/13081310/combining-multiple-complex-plots-as-panels-in-a-single-figure
- https://kohske.wordpress.com/2010/12/29/faq-how-to-order-the-factor-variables-in-ggplot2/
Type
- http://rgraphgallery.blogspot.com/search/label/boxplot
Multiple data series
- http://www.sixhat.net/how-to-plot-multpile-data-series-with-ggplot.html
- http://stackoverflow.com/questions/10357768/plotting-lines-and-the-group-aesthetic-in-ggplot2
- http://www.cookbook-r.com/Graphs/Colors_%28ggplot2%29/
Bubble Chart
[e.g.#1]
#updated for ggplot 0.9.1
crime <-
read.csv
(
"http://datasets.flowingdata.com/crimeRatesByState2005.tsv"
, header=
TRUE
, sep=
"\t"
)
ggplot
(crime,
aes
(x=murder, y=burglary, size=population, label=state),guide=
FALSE
)+
geom_point
(colour=
"white"
, fill=
"red"
, shape=21)+
scale_area
(range=
c
(1,25))+
scale_x_continuous
(name=
"Murders per 1,000 population"
, limits=
c
(0,12))+
scale_y_continuous
(name=
"Burglaries per 1,000 population"
, limits=
c
(0,1250))+
geom_text
(size=4)+
theme_bw
()
[e.g. #1-2]
#crime <-read.csv("http://datasets.flowingdata.com/crimeRatesByState2005.tsv", header=TRUE, sep="\t")
crime <- read.csv("http://datasets.flowingdata.com/crimeRatesByState2008.csv", header=TRUE, sep="\t")
p = ggplot(crime, aes(murder,burglary,size=population, label=state))
p = p+geom_point(colour="red") +scale_area(to=c(1,20))+geom_text(size=3)
p + xlab("Murders per 1,000 population") + ylab("Burglaries per 1,000")
[e.g.3]
crime <- read.csv("http://datasets.flowingdata.com/crimeRatesByState2005.tsv", header=TRUE, sep="\t" )
symbols(crime$murder, crime$burglary, circles=crime$population)
radius <- sqrt( crime$population/ pi )
symbols(crime$murder, crime$burglary, circles=radius)
symbols(crime$murder, crime$burglary, circles=radius, inches=0.35, fg="white", bg="red", xlab="Murder Rate", ylab="Burglary Rate")
symbols(crime$murder, crime$burglary, squares=sqrt(crime$population), inches=0.5)
text(crime$murder, crime$burglary, crime$state, cex=0.5)
[e.g. #2] ????
ggplot
(asd_data,
aes
(x=prev2003, y=asd_diff, weight=denom2003, colour=octile, size=denom2003)) +
geom_point
( alpha=0.8, guide=
"none"
) +
scale_size_area
(breaks=
c
(250, 500, 1000, 10000, 50000),
"2002 District\nElementary School\nPopulation"
, max_size=20) +
stat_smooth
(method=
"rlm"
, size=0.5, colour=
"black"
, alpha=0.4, level=0.95)+
scale_colour_brewer
(palette=
"Spectral"
, type=
"qual"
,name=
"2002 Autism\nPrevalence Octile"
) +
coord_equal
(ratio=1/2)+
guides
(colour =
guide_legend
(override.aes =
list
(alpha = 1)))+
ggtitle
("Figure 4. Change
in
Autism Prevalence between 2002 and 2008 vs
Baseline
(2002) Prevalence,\n
Wisconsin Elementary School
Districts
(with weighted linear best-fit line and 95% confidence band)") +
scale_x_continuous
(
"2002 Autism Prevalence (per 1,000)"
) +
scale_y_continuous
(
"Change in Autism Prevalence (per 1,000) between 2002 and 2008"
)
[e.g.3]
library(googleVis)
bubbleChart <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales",
yvar="Expenses", sizevar="Profit",
options=list(hAxis='{minValue:75,
maxValue:125}',
width=500, height=300,
colorAxis="{colors: ['lightblue', 'blue']}"),
chartid="Bubble_Chart_colour_Axis"
)
plot(bubbleChart)
[final]
library(ggplot2)
# Datasets
prc = read.csv("http://ichart.finance.yahoo.com/table.csv?s=^GSPC&d=0&e=1&f=2013&g=m&a=0&b=1&c=1990&ignore=.csv", as.is=T)
vix = read.csv("http://ichart.finance.yahoo.com/table.csv?s=%5EVIX&a=00&b=2&c=1990&d=0&e=1&f=2013&g=m&ignore=.csv", as.is=T)
# Data processing
prc$Date <- as.Date(prc$Date)
prc <- prc[, c(1,7)]
colnames(prc)[2] <-c("Value")
vix$Date <- as.Date(vix$Date)
vix <- vix[, c(1,5)]
colnames(vix)[2] <-c("VIX")
df = merge(prc, vix)
df$year = as.integer(substring(df$Date,1,4))
df$month = as.integer(substring(df$Date,6,7))
# Graphs
par(mfrow=c(2,1))
plot(df$Date, df$Value, type="l",main="S&P500", xlab="", ylab="")
plot(df$Date, df$VIX, type="l",main="VIX ( VOLATILITY S&P 500) ", xlab="", ylab="")
# Erase
frame()
par(mfrow=c(1,1))
# ggplot2 base layer
p = ggplot(df)
# Line graph
(
p
+ geom_line( aes(x=df$Date, y=df$Value, colour=VIX ) )
+ scale_colour_gradient(low="blue", high="red")
)
# Bubble plots
(
p
+ geom_point(aes(x = month, y = year, size = Value, colour = VIX),shape=16, alpha=0.80)
+ scale_colour_gradient(limits = c(10, 60), low="blue", high="red", breaks= seq(10, 60, by = 10))
+ scale_x_continuous(breaks = 1:12, labels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
+ scale_y_continuous(trans = "reverse")
)
df= NULL
df$exp = c(1,2,3)
df$cna = c(1,2,3)
df$met = c(1,2,3)
df$name = c("aaa", "bbb","ccc" )
df = as.data.frame( df )
p = ggplot( df )
(
p
+ geom_line( aes( x=cna, y=met, color=exp ) )
+ scale_colour_gradient(low="blue", high="red")
)
p = ggplot( df )
(
p
+ geom_point( aes( x=cna, y=met, size=exp, color=exp), shape=16, alpha=0.5)
+ scale_colour_gradient(limits = c(0, 5), low="blue", high="red", breaks= seq(0, 5, by = 1))
+ geom_text( aes(x=cna, y=met, label=name), hjust=0, vjust=2, angle=0 )
)
#ggplot(nba, aes(x= MIN, y= PTS, colour="green", label=Name))+
# geom_point() +geom_text(aes(label=Name),hjust=0, vjust=0)
-----------------
require( ggplot2 )
p = ggplot( t )
(
p
#+ geom_point( aes( x=cna, y=met, size=exp, color=exp), shape=exp, alpha=0.)
#+ geom_jitter( aes( x=cna, y=met), position = #position_jitter(width = .5))
+ geom_point( aes( x=cna, y=met, fill=exp), color="black", shape=21, size=7, alpha=1, position=position_jitter(w=0, h=0))
#+ scale_fill_gradientn(colours = topo.colors(10), breaks=seq(-10,10, by=5) )
+ scale_fill_gradient2(limits = c(-10, 10), low="blue", mid="yellow", high="red", breaks= seq(-10, 10, by=5))
+ geom_text( aes(x=cna, y=met, label=label2), hjust=-0.3, vjust=0.5, angle=30, size=3.2, position = position_jitter(width=0, height=0))
+ labs( x="Reccurrent (%) Copy-number Change \n(+:gain | -:loss)", y="Promoter Methylation \n(+:hyper- / -:hypo-methylation)", fill="Expression \nFold Change", size=20)
#+ theme_bw()
+ geom_vline(xintercept = 0, colour="green", linetype = "longdash")
+ geom_hline(yintercept = 0, colour="green", linetype = "longdash")
+ theme(axis.text=element_text(size=12),
axis.title=element_text(size=14,face="bold", color="black"),
legend.title=element_text( size=14),
legend.position = c(0.9, 0.9))
)
이메일로 전송BlogThis!Twitter에서 공유Facebook에서 공유
라벨:
Informatics
#updated for ggplot 0.9.1
crime <-
read.csv
(
"http://datasets.flowingdata.com/crimeRatesByState2005.tsv"
, header=
TRUE
, sep=
"\t"
)
ggplot
(crime,
aes
(x=murder, y=burglary, size=population, label=state),guide=
FALSE
)+
geom_point
(colour=
"white"
, fill=
"red"
, shape=21)+
scale_area
(range=
c
(1,25))+
scale_x_continuous
(name=
"Murders per 1,000 population"
, limits=
c
(0,12))+
scale_y_continuous
(name=
"Burglaries per 1,000 population"
, limits=
c
(0,1250))+
geom_text
(size=4)+
theme_bw
()
#crime <-read.csv("http://datasets.flowingdata.com/crimeRatesByState2005.tsv", header=TRUE, sep="\t")
p = ggplot(crime, aes(murder,burglary,size=population, label=state)) p = p+geom_point(colour="red") +scale_area(to=c(1,20))+geom_text(size=3)
p + xlab("Murders per 1,000 population") + ylab("Burglaries per 1,000")
crime <- read.csv("http://datasets.flowingdata.com/crimeRatesByState2005.tsv", header=TRUE, sep="\t" )
symbols(crime$murder, crime$burglary, circles=crime$population)
[e.g. #2]
????
ggplot
(asd_data,
aes
(x=prev2003, y=asd_diff, weight=denom2003, colour=octile, size=denom2003)) +
geom_point
( alpha=0.8, guide=
"none"
) +
scale_size_area
(breaks=
c
(250, 500, 1000, 10000, 50000),
"2002 District\nElementary School\nPopulation"
, max_size=20) +
stat_smooth
(method=
"rlm"
, size=0.5, colour=
"black"
, alpha=0.4, level=0.95)+
scale_colour_brewer
(palette=
"Spectral"
, type=
"qual"
,name=
"2002 Autism\nPrevalence Octile"
) +
coord_equal
(ratio=1/2)+
guides
(colour =
guide_legend
(override.aes =
list
(alpha = 1)))+
ggtitle
("Figure 4. Change
in
Autism Prevalence between 2002 and 2008 vs
Baseline
(2002) Prevalence,\n
Wisconsin Elementary School
Districts
(with weighted linear best-fit line and 95% confidence band)") +
scale_x_continuous
(
"2002 Autism Prevalence (per 1,000)"
) +
scale_y_continuous
(
"Change in Autism Prevalence (per 1,000) between 2002 and 2008"
)
library(googleVis)bubbleChart <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales",yvar="Expenses", sizevar="Profit",options=list(hAxis='{minValue:75,maxValue:125}',width=500, height=300,colorAxis="{colors: ['lightblue', 'blue']}"),chartid="Bubble_Chart_colour_Axis")plot(bubbleChart)[final]
library(ggplot2) # Datasets prc = read.csv("http://ichart.finance.yahoo.com/table.csv?s=^GSPC&d=0&e=1&f=2013&g=m&a=0&b=1&c=1990&ignore=.csv", as.is=T) vix = read.csv("http://ichart.finance.yahoo.com/table.csv?s=%5EVIX&a=00&b=2&c=1990&d=0&e=1&f=2013&g=m&ignore=.csv", as.is=T) # Data processing prc$Date <- as.Date(prc$Date) prc <- prc[, c(1,7)] colnames(prc)[2] <-c("Value") vix$Date <- as.Date(vix$Date) vix <- vix[, c(1,5)] colnames(vix)[2] <-c("VIX") df = merge(prc, vix) df$year = as.integer(substring(df$Date,1,4)) df$month = as.integer(substring(df$Date,6,7)) # Graphs par(mfrow=c(2,1)) plot(df$Date, df$Value, type="l",main="S&P500", xlab="", ylab="") plot(df$Date, df$VIX, type="l",main="VIX ( VOLATILITY S&P 500) ", xlab="", ylab="") # Erase frame() par(mfrow=c(1,1)) # ggplot2 base layer p = ggplot(df) # Line graph ( p
+ geom_line( aes(x=df$Date, y=df$Value, colour=VIX ) )
+ scale_colour_gradient(low="blue", high="red")
)
# Bubble plots (
p
+ geom_point(aes(x = month, y = year, size = Value, colour = VIX),shape=16, alpha=0.80)
+ scale_colour_gradient(limits = c(10, 60), low="blue", high="red", breaks= seq(10, 60, by = 10))
+ scale_x_continuous(breaks = 1:12, labels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
+ scale_y_continuous(trans = "reverse")
)
df= NULL df$exp = c(1,2,3)
df$cna = c(1,2,3)
df$met = c(1,2,3)
df$name = c("aaa", "bbb","ccc" )
df = as.data.frame( df )
p = ggplot( df )
(
p
+ geom_line( aes( x=cna, y=met, color=exp ) )
+ scale_colour_gradient(low="blue", high="red")
)
p = ggplot( df )
(
p
+ geom_point( aes( x=cna, y=met, size=exp, color=exp), shape=16, alpha=0.5)
+ scale_colour_gradient(limits = c(0, 5), low="blue", high="red", breaks= seq(0, 5, by = 1))
+ geom_text( aes(x=cna, y=met, label=name), hjust=0, vjust=2, angle=0 )
)
#ggplot(nba, aes(x= MIN, y= PTS, colour="green", label=Name))+
# geom_point() +geom_text(aes(label=Name),hjust=0, vjust=0)
-----------------
require( ggplot2 ) p = ggplot( t ) ( p #+ geom_point( aes( x=cna, y=met, size=exp, color=exp), shape=exp, alpha=0.) #+ geom_jitter( aes( x=cna, y=met), position = #position_jitter(width = .5)) + geom_point( aes( x=cna, y=met, fill=exp), color="black", shape=21, size=7, alpha=1, position=position_jitter(w=0, h=0)) #+ scale_fill_gradientn(colours = topo.colors(10), breaks=seq(-10,10, by=5) ) + scale_fill_gradient2(limits = c(-10, 10), low="blue", mid="yellow", high="red", breaks= seq(-10, 10, by=5)) + geom_text( aes(x=cna, y=met, label=label2), hjust=-0.3, vjust=0.5, angle=30, size=3.2, position = position_jitter(width=0, height=0)) + labs( x="Reccurrent (%) Copy-number Change \n(+:gain | -:loss)", y="Promoter Methylation \n(+:hyper- / -:hypo-methylation)", fill="Expression \nFold Change", size=20) #+ theme_bw() + geom_vline(xintercept = 0, colour="green", linetype = "longdash") + geom_hline(yintercept = 0, colour="green", linetype = "longdash") + theme(axis.text=element_text(size=12), axis.title=element_text(size=14,face="bold", color="black"), legend.title=element_text( size=14), legend.position = c(0.9, 0.9)) )
Scientist. Husband. Daddy. --- TOLLE. LEGE
외부자료의 인용에 있어 대한민국 저작권법(28조)과 U.S. Copyright Act (17 USC. §107)에 정의된 "저작권물의 공정한 이용원칙 | the U.S. fair use doctrine" 을 따릅니다. 저작권(© 최광민)이 명시된 모든 글과 번역문들에 대해 (1) 복제-배포, (2) 임의수정 및 자의적 본문 발췌, (3) 무단배포를 위한 화면캡처를 금하며, (4) 인용 시 URL 주소 만을 사용할 수 있습니다. [후원 | 운영] [대문으로] [방명록] [옛 방명록] [티스토리 (백업)] [신시내티]
-