imagebar {patternplot} | R Documentation |
Plot a bar chart with bars filled with png and jpeg images.
Description
The imagebar
function is a tool for creating versatile bar charts by filling the bars with external png and jpeg images.
Usage
imagebar(
data,
x,
y,
group = NULL,
xlab = "",
ylab = "",
label.size = 3.5,
vjust = -1,
hjust = -1,
pattern.type,
frame.color = "black",
frame.size = 1,
legend.type = "h",
legend.h = 6,
legend.x.pos = 1.1,
legend.y.pos = 0.49,
legend.w = 0.2,
legend.pixel = 0.3,
bar.width = 0.9
)
Arguments
data |
the data to be used. |
x |
the variable used on x axis. |
y |
the variable used on y axis. |
group |
the variable used as the second grouping variable on x axis. |
xlab |
a character string to give x axis label. |
ylab |
a character string to give y axis label. |
label.size |
the font size of legend labels shown above the bars. |
vjust |
the vertical distance of labels from the top border of each bar. |
hjust |
the horizontal distance of labels from the top border of each bar. |
pattern.type |
a list of objects returned by |
frame.color |
the color of the borders of bars. |
frame.size |
a numeric value, the line size for the borders of bars. |
legend.type |
if legend.type='h', the layout of legends is horizontal; if legend.type='v', the layout of legends is vertical. |
legend.h |
a numeric value to change the height of legend boxes. |
legend.x.pos |
a numeric value to change the position of legends on x axis. |
legend.y.pos |
a numeric value to change the position of legends on y axis. |
legend.w |
a numeric value to change the width of legends. |
legend.pixel |
a numeric value to change the pixel of legend boxes |
bar.width |
a numeric value to change the width of the bars. |
Details
imagebar
function offers flexible ways of doing bar charts.
Value
A ggplot object.
Author(s)
Chunqiao Luo (chunqiaoluo@gmail.com)
See Also
Function patternbar
Examples
library(patternplot)
library(jpeg)
library(ggplot2)
childcare<-readJPEG(system.file("img", "childcare.jpg", package="patternplot"))
food<-readJPEG(system.file("img", "food.jpg", package="patternplot"))
housing <-readJPEG(system.file("img", "housing.jpg", package="patternplot"))
#Example 1
data <- read.csv(system.file("extdata", "monthlyexp.csv", package="patternplot"))
data<-data[which(data$Location=='City 1'),]
x<-factor(data$Type, c('Housing', 'Food', 'Childcare'))
y<-data$Amount
pattern.type<-list(housing, food, childcare)
imagebar(data,x, y,group=NULL,pattern.type=pattern.type,vjust=-1, hjust=0.5,
frame.color='black',ylab='Monthly Expenses, Dollars')+ggtitle('(A) Bar Chart with Images')
#Example 2
data <- read.csv(system.file("extdata", "monthlyexp.csv", package="patternplot"))
group<-factor(data$Type, c('Housing', 'Food', 'Childcare'))
y<-data$Amount
x<-factor(data$Location, c('City 1', ' City 1'))
pattern.type<-list(housing, food, childcare)
g<-imagebar(data,x,y,group,pattern.type=pattern.type,vjust=-1,hjust=0.5,frame.color='black',
ylab='Monthly Expenses, Dollars')+ggtitle('(B) Image Bar Chart with Two Grouping Variables')