How to add geom_line to a grouped barplot [duplicate]
up vote
-1
down vote
favorite
This question already has an answer here:
ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
3 answers
How can a line be overlaid on a bar plot using ggplot2?
2 answers
I am trying to create a grouped bar chart with a line over it. The geom_bar and geom_line seem to work together when it is a single barchart however not when it is a grouped one. This is my code below which shows the barchart perfectly however does not show the line. The error message I am getting is: "geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?"
Below is my code, does anyone know how to fix this?
cbPalette <- c("grey20", "grey","black")
x <- read.csv("cuss_usage2.csv", header=TRUE, sep=",")
z <- read.csv("cuss_usage3.csv", header=TRUE, sep=",")
y <- data.frame (x)
a <-data.frame(z)
bar <- ggplot (group, aes(x=day, y=value)) +
geom_bar(aes(x=day, y=value,fill=variable),stat="identity",
position="dodge") +
geom_line(data=a, aes(x=day,y=percentage),color="black") +
scale_x_discrete(limits=c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sun")) +
scale_y_discrete(limits=c(0,2,4,6,8,10)) +
scale_fill_manual(values=cbPalette) + theme(legend.position="bottom")
+labs(fill="")+ylab("Journey Time (min)")+xlab("")
grid.arrange(bar)
Below is my csv data for bar plot:
day,pax,count
Mon,4,9
Tue,5,8
Wed,7,7
Thu,9,3
Fri,4,6
Sat,3,9
Sun,2,7
Below is my csv data for line:
day,percentage
Mon,5
Tue,5
Wed,3
Thu,5
Fri,2
Sat,4
Sun,3
r ggplot2 bar-chart
marked as duplicate by Jaap
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 16:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-1
down vote
favorite
This question already has an answer here:
ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
3 answers
How can a line be overlaid on a bar plot using ggplot2?
2 answers
I am trying to create a grouped bar chart with a line over it. The geom_bar and geom_line seem to work together when it is a single barchart however not when it is a grouped one. This is my code below which shows the barchart perfectly however does not show the line. The error message I am getting is: "geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?"
Below is my code, does anyone know how to fix this?
cbPalette <- c("grey20", "grey","black")
x <- read.csv("cuss_usage2.csv", header=TRUE, sep=",")
z <- read.csv("cuss_usage3.csv", header=TRUE, sep=",")
y <- data.frame (x)
a <-data.frame(z)
bar <- ggplot (group, aes(x=day, y=value)) +
geom_bar(aes(x=day, y=value,fill=variable),stat="identity",
position="dodge") +
geom_line(data=a, aes(x=day,y=percentage),color="black") +
scale_x_discrete(limits=c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sun")) +
scale_y_discrete(limits=c(0,2,4,6,8,10)) +
scale_fill_manual(values=cbPalette) + theme(legend.position="bottom")
+labs(fill="")+ylab("Journey Time (min)")+xlab("")
grid.arrange(bar)
Below is my csv data for bar plot:
day,pax,count
Mon,4,9
Tue,5,8
Wed,7,7
Thu,9,3
Fri,4,6
Sat,3,9
Sun,2,7
Below is my csv data for line:
day,percentage
Mon,5
Tue,5
Wed,3
Thu,5
Fri,2
Sat,4
Sun,3
r ggplot2 bar-chart
marked as duplicate by Jaap
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 16:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Your code doesn't match your variable names, please revise. There are nogroup
,value
, andvariable
.
– Anonymous coward
Nov 21 at 15:48
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
This question already has an answer here:
ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
3 answers
How can a line be overlaid on a bar plot using ggplot2?
2 answers
I am trying to create a grouped bar chart with a line over it. The geom_bar and geom_line seem to work together when it is a single barchart however not when it is a grouped one. This is my code below which shows the barchart perfectly however does not show the line. The error message I am getting is: "geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?"
Below is my code, does anyone know how to fix this?
cbPalette <- c("grey20", "grey","black")
x <- read.csv("cuss_usage2.csv", header=TRUE, sep=",")
z <- read.csv("cuss_usage3.csv", header=TRUE, sep=",")
y <- data.frame (x)
a <-data.frame(z)
bar <- ggplot (group, aes(x=day, y=value)) +
geom_bar(aes(x=day, y=value,fill=variable),stat="identity",
position="dodge") +
geom_line(data=a, aes(x=day,y=percentage),color="black") +
scale_x_discrete(limits=c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sun")) +
scale_y_discrete(limits=c(0,2,4,6,8,10)) +
scale_fill_manual(values=cbPalette) + theme(legend.position="bottom")
+labs(fill="")+ylab("Journey Time (min)")+xlab("")
grid.arrange(bar)
Below is my csv data for bar plot:
day,pax,count
Mon,4,9
Tue,5,8
Wed,7,7
Thu,9,3
Fri,4,6
Sat,3,9
Sun,2,7
Below is my csv data for line:
day,percentage
Mon,5
Tue,5
Wed,3
Thu,5
Fri,2
Sat,4
Sun,3
r ggplot2 bar-chart
This question already has an answer here:
ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
3 answers
How can a line be overlaid on a bar plot using ggplot2?
2 answers
I am trying to create a grouped bar chart with a line over it. The geom_bar and geom_line seem to work together when it is a single barchart however not when it is a grouped one. This is my code below which shows the barchart perfectly however does not show the line. The error message I am getting is: "geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?"
Below is my code, does anyone know how to fix this?
cbPalette <- c("grey20", "grey","black")
x <- read.csv("cuss_usage2.csv", header=TRUE, sep=",")
z <- read.csv("cuss_usage3.csv", header=TRUE, sep=",")
y <- data.frame (x)
a <-data.frame(z)
bar <- ggplot (group, aes(x=day, y=value)) +
geom_bar(aes(x=day, y=value,fill=variable),stat="identity",
position="dodge") +
geom_line(data=a, aes(x=day,y=percentage),color="black") +
scale_x_discrete(limits=c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sun")) +
scale_y_discrete(limits=c(0,2,4,6,8,10)) +
scale_fill_manual(values=cbPalette) + theme(legend.position="bottom")
+labs(fill="")+ylab("Journey Time (min)")+xlab("")
grid.arrange(bar)
Below is my csv data for bar plot:
day,pax,count
Mon,4,9
Tue,5,8
Wed,7,7
Thu,9,3
Fri,4,6
Sat,3,9
Sun,2,7
Below is my csv data for line:
day,percentage
Mon,5
Tue,5
Wed,3
Thu,5
Fri,2
Sat,4
Sun,3
This question already has an answer here:
ggplot2 line chart gives “geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?”
3 answers
How can a line be overlaid on a bar plot using ggplot2?
2 answers
r ggplot2 bar-chart
r ggplot2 bar-chart
edited Nov 21 at 16:21
asked Nov 21 at 15:26
Lydia Blakley
25
25
marked as duplicate by Jaap
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 16:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Jaap
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 16:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Your code doesn't match your variable names, please revise. There are nogroup
,value
, andvariable
.
– Anonymous coward
Nov 21 at 15:48
add a comment |
Your code doesn't match your variable names, please revise. There are nogroup
,value
, andvariable
.
– Anonymous coward
Nov 21 at 15:48
Your code doesn't match your variable names, please revise. There are no
group
, value
, and variable
.– Anonymous coward
Nov 21 at 15:48
Your code doesn't match your variable names, please revise. There are no
group
, value
, and variable
.– Anonymous coward
Nov 21 at 15:48
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code doesn't match your variable names, please revise. There are no
group
,value
, andvariable
.– Anonymous coward
Nov 21 at 15:48