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









share|improve this question















marked as duplicate by Jaap r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

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 no group, value, and variable.
    – Anonymous coward
    Nov 21 at 15:48















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









share|improve this question















marked as duplicate by Jaap r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

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 no group, value, and variable.
    – Anonymous coward
    Nov 21 at 15:48













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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 16:21

























asked Nov 21 at 15:26









Lydia Blakley

25




25




marked as duplicate by Jaap r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

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 r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

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 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
















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

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks