imagebar: Plot a bar chart with bars filled with png and jpeg images.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/imagebar.R

Description

The imagebar function is a tool for creating versatile bar charts by filling the bars with external png and jpeg images.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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 readPNG and readJPEG used to fill the bars.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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')

patternplot documentation built on April 21, 2020, 5:05 p.m.