how to map more than 10 different line types in ggplot2












0















I have to map 11 different line types, trying to use scale_linetype_manual to specify that but unable to do that.



dat <- data.frame(Subject = c(1,1,1,2,2,2,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,10,10,10,11,11,11),
Time = c("C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C1D1","C1D8","C2D1"," C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D 1","C1D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1"),
Response = c("Responder","Responder","Responder","Progressive","Progressive","Progressive", "Non-evaluable","Non-evaluable","Non-evaluable","Non-evaluable","Non- evaluable","Stable","Stable","Stable","Progressive","Progressive","Progressive", "Progressive","Progressive","Progressive","Non-evaluable","Non- evaluable","Non-evaluable","Non-evaluable","Stable","Stable","Stable","Non- evaluable","Non-evaluable","Non-evaluable"),
Eotaxin = c(401.5,463,363.5,332.5,319,212,527.5,421.5,369.5,535,221.5,936.5,1021.5,550.5,4 58.5,386,340,172.5,212.5,160.5,267,301,300.5,300.5,1160,1018,994.5,197,392.5,220 .5)
)

dat$Subject <- as.character(dat$Subject)

nms <- names(dat)

for(biomark in 4:4){

#png(filename = paste("../../../Roswell/plot/",nms[biomark],".png",sep = ""),width = 1500,height = 1000,res = 200)


p <- ggplot() +
geom_line(data = dat, aes(x = dat$Time, y = dat[,biomark],group = dat$Subject, linetype = Subject, colour = Response)) +
labs(title = nms[biomark]) +
scale_linetype_manual(breaks = c("1","2","3","4","5","6","7","8","9","10","11"),
values = c("dotted", "solid", "dashed", "F1", "solid", "solid", "solid", "solid", "solid", "solid", "solid")) +
xlab("Time") +
ylab(nms[biomark]) +
theme_minimal() +
theme(plot.title = element_text(size = 12,face="bold",hjust = 0.5),
axis.title = element_text(size= 12, face = "bold"),
legend.text = element_text(size = 7),
legend.title = element_text(size = 7,face = "bold"),
legend.key.size = unit(0.5, "cm"))


plot(p)


#dev.off()

}


The plot shows that why the line type legends do not match what specified in scale_linetype_manual especially for the first 4 types, the third and fourth types are still solid when I specified "dashed" and "F1"?
resulted plot










share|improve this question

























  • It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Right now we have no idea what your data actually looks like.

    – MrFlick
    Nov 14 '18 at 16:54






  • 1





    Will this really be a graph that's easy to read? Perhaps using different ggplot syntax meant for differentiating between distributions is more fitting (facet, color etc)?

    – 12b345b6b78
    Nov 14 '18 at 16:55






  • 2





    aes() expects unquoted column names, change to aes(x = Time, y = biomark, group = Subject, linetype = Subject, colour = Response).With those changes all your labs should be set correctly by default. It may help with your linetype problem as well.

    – Gregor
    Nov 14 '18 at 16:56













  • sample data is provided, thx @MrFlick

    – dotahuanci
    Nov 14 '18 at 17:35
















0















I have to map 11 different line types, trying to use scale_linetype_manual to specify that but unable to do that.



dat <- data.frame(Subject = c(1,1,1,2,2,2,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,10,10,10,11,11,11),
Time = c("C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C1D1","C1D8","C2D1"," C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D 1","C1D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1"),
Response = c("Responder","Responder","Responder","Progressive","Progressive","Progressive", "Non-evaluable","Non-evaluable","Non-evaluable","Non-evaluable","Non- evaluable","Stable","Stable","Stable","Progressive","Progressive","Progressive", "Progressive","Progressive","Progressive","Non-evaluable","Non- evaluable","Non-evaluable","Non-evaluable","Stable","Stable","Stable","Non- evaluable","Non-evaluable","Non-evaluable"),
Eotaxin = c(401.5,463,363.5,332.5,319,212,527.5,421.5,369.5,535,221.5,936.5,1021.5,550.5,4 58.5,386,340,172.5,212.5,160.5,267,301,300.5,300.5,1160,1018,994.5,197,392.5,220 .5)
)

dat$Subject <- as.character(dat$Subject)

nms <- names(dat)

for(biomark in 4:4){

#png(filename = paste("../../../Roswell/plot/",nms[biomark],".png",sep = ""),width = 1500,height = 1000,res = 200)


p <- ggplot() +
geom_line(data = dat, aes(x = dat$Time, y = dat[,biomark],group = dat$Subject, linetype = Subject, colour = Response)) +
labs(title = nms[biomark]) +
scale_linetype_manual(breaks = c("1","2","3","4","5","6","7","8","9","10","11"),
values = c("dotted", "solid", "dashed", "F1", "solid", "solid", "solid", "solid", "solid", "solid", "solid")) +
xlab("Time") +
ylab(nms[biomark]) +
theme_minimal() +
theme(plot.title = element_text(size = 12,face="bold",hjust = 0.5),
axis.title = element_text(size= 12, face = "bold"),
legend.text = element_text(size = 7),
legend.title = element_text(size = 7,face = "bold"),
legend.key.size = unit(0.5, "cm"))


plot(p)


#dev.off()

}


The plot shows that why the line type legends do not match what specified in scale_linetype_manual especially for the first 4 types, the third and fourth types are still solid when I specified "dashed" and "F1"?
resulted plot










share|improve this question

























  • It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Right now we have no idea what your data actually looks like.

    – MrFlick
    Nov 14 '18 at 16:54






  • 1





    Will this really be a graph that's easy to read? Perhaps using different ggplot syntax meant for differentiating between distributions is more fitting (facet, color etc)?

    – 12b345b6b78
    Nov 14 '18 at 16:55






  • 2





    aes() expects unquoted column names, change to aes(x = Time, y = biomark, group = Subject, linetype = Subject, colour = Response).With those changes all your labs should be set correctly by default. It may help with your linetype problem as well.

    – Gregor
    Nov 14 '18 at 16:56













  • sample data is provided, thx @MrFlick

    – dotahuanci
    Nov 14 '18 at 17:35














0












0








0








I have to map 11 different line types, trying to use scale_linetype_manual to specify that but unable to do that.



dat <- data.frame(Subject = c(1,1,1,2,2,2,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,10,10,10,11,11,11),
Time = c("C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C1D1","C1D8","C2D1"," C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D 1","C1D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1"),
Response = c("Responder","Responder","Responder","Progressive","Progressive","Progressive", "Non-evaluable","Non-evaluable","Non-evaluable","Non-evaluable","Non- evaluable","Stable","Stable","Stable","Progressive","Progressive","Progressive", "Progressive","Progressive","Progressive","Non-evaluable","Non- evaluable","Non-evaluable","Non-evaluable","Stable","Stable","Stable","Non- evaluable","Non-evaluable","Non-evaluable"),
Eotaxin = c(401.5,463,363.5,332.5,319,212,527.5,421.5,369.5,535,221.5,936.5,1021.5,550.5,4 58.5,386,340,172.5,212.5,160.5,267,301,300.5,300.5,1160,1018,994.5,197,392.5,220 .5)
)

dat$Subject <- as.character(dat$Subject)

nms <- names(dat)

for(biomark in 4:4){

#png(filename = paste("../../../Roswell/plot/",nms[biomark],".png",sep = ""),width = 1500,height = 1000,res = 200)


p <- ggplot() +
geom_line(data = dat, aes(x = dat$Time, y = dat[,biomark],group = dat$Subject, linetype = Subject, colour = Response)) +
labs(title = nms[biomark]) +
scale_linetype_manual(breaks = c("1","2","3","4","5","6","7","8","9","10","11"),
values = c("dotted", "solid", "dashed", "F1", "solid", "solid", "solid", "solid", "solid", "solid", "solid")) +
xlab("Time") +
ylab(nms[biomark]) +
theme_minimal() +
theme(plot.title = element_text(size = 12,face="bold",hjust = 0.5),
axis.title = element_text(size= 12, face = "bold"),
legend.text = element_text(size = 7),
legend.title = element_text(size = 7,face = "bold"),
legend.key.size = unit(0.5, "cm"))


plot(p)


#dev.off()

}


The plot shows that why the line type legends do not match what specified in scale_linetype_manual especially for the first 4 types, the third and fourth types are still solid when I specified "dashed" and "F1"?
resulted plot










share|improve this question
















I have to map 11 different line types, trying to use scale_linetype_manual to specify that but unable to do that.



dat <- data.frame(Subject = c(1,1,1,2,2,2,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,10,10,10,11,11,11),
Time = c("C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C1D1","C1D8","C2D1"," C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D 1","C1D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1"),
Response = c("Responder","Responder","Responder","Progressive","Progressive","Progressive", "Non-evaluable","Non-evaluable","Non-evaluable","Non-evaluable","Non- evaluable","Stable","Stable","Stable","Progressive","Progressive","Progressive", "Progressive","Progressive","Progressive","Non-evaluable","Non- evaluable","Non-evaluable","Non-evaluable","Stable","Stable","Stable","Non- evaluable","Non-evaluable","Non-evaluable"),
Eotaxin = c(401.5,463,363.5,332.5,319,212,527.5,421.5,369.5,535,221.5,936.5,1021.5,550.5,4 58.5,386,340,172.5,212.5,160.5,267,301,300.5,300.5,1160,1018,994.5,197,392.5,220 .5)
)

dat$Subject <- as.character(dat$Subject)

nms <- names(dat)

for(biomark in 4:4){

#png(filename = paste("../../../Roswell/plot/",nms[biomark],".png",sep = ""),width = 1500,height = 1000,res = 200)


p <- ggplot() +
geom_line(data = dat, aes(x = dat$Time, y = dat[,biomark],group = dat$Subject, linetype = Subject, colour = Response)) +
labs(title = nms[biomark]) +
scale_linetype_manual(breaks = c("1","2","3","4","5","6","7","8","9","10","11"),
values = c("dotted", "solid", "dashed", "F1", "solid", "solid", "solid", "solid", "solid", "solid", "solid")) +
xlab("Time") +
ylab(nms[biomark]) +
theme_minimal() +
theme(plot.title = element_text(size = 12,face="bold",hjust = 0.5),
axis.title = element_text(size= 12, face = "bold"),
legend.text = element_text(size = 7),
legend.title = element_text(size = 7,face = "bold"),
legend.key.size = unit(0.5, "cm"))


plot(p)


#dev.off()

}


The plot shows that why the line type legends do not match what specified in scale_linetype_manual especially for the first 4 types, the third and fourth types are still solid when I specified "dashed" and "F1"?
resulted plot







r types line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 17:34







dotahuanci

















asked Nov 14 '18 at 16:48









dotahuancidotahuanci

63




63













  • It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Right now we have no idea what your data actually looks like.

    – MrFlick
    Nov 14 '18 at 16:54






  • 1





    Will this really be a graph that's easy to read? Perhaps using different ggplot syntax meant for differentiating between distributions is more fitting (facet, color etc)?

    – 12b345b6b78
    Nov 14 '18 at 16:55






  • 2





    aes() expects unquoted column names, change to aes(x = Time, y = biomark, group = Subject, linetype = Subject, colour = Response).With those changes all your labs should be set correctly by default. It may help with your linetype problem as well.

    – Gregor
    Nov 14 '18 at 16:56













  • sample data is provided, thx @MrFlick

    – dotahuanci
    Nov 14 '18 at 17:35



















  • It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Right now we have no idea what your data actually looks like.

    – MrFlick
    Nov 14 '18 at 16:54






  • 1





    Will this really be a graph that's easy to read? Perhaps using different ggplot syntax meant for differentiating between distributions is more fitting (facet, color etc)?

    – 12b345b6b78
    Nov 14 '18 at 16:55






  • 2





    aes() expects unquoted column names, change to aes(x = Time, y = biomark, group = Subject, linetype = Subject, colour = Response).With those changes all your labs should be set correctly by default. It may help with your linetype problem as well.

    – Gregor
    Nov 14 '18 at 16:56













  • sample data is provided, thx @MrFlick

    – dotahuanci
    Nov 14 '18 at 17:35

















It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Right now we have no idea what your data actually looks like.

– MrFlick
Nov 14 '18 at 16:54





It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. Right now we have no idea what your data actually looks like.

– MrFlick
Nov 14 '18 at 16:54




1




1





Will this really be a graph that's easy to read? Perhaps using different ggplot syntax meant for differentiating between distributions is more fitting (facet, color etc)?

– 12b345b6b78
Nov 14 '18 at 16:55





Will this really be a graph that's easy to read? Perhaps using different ggplot syntax meant for differentiating between distributions is more fitting (facet, color etc)?

– 12b345b6b78
Nov 14 '18 at 16:55




2




2





aes() expects unquoted column names, change to aes(x = Time, y = biomark, group = Subject, linetype = Subject, colour = Response).With those changes all your labs should be set correctly by default. It may help with your linetype problem as well.

– Gregor
Nov 14 '18 at 16:56







aes() expects unquoted column names, change to aes(x = Time, y = biomark, group = Subject, linetype = Subject, colour = Response).With those changes all your labs should be set correctly by default. It may help with your linetype problem as well.

– Gregor
Nov 14 '18 at 16:56















sample data is provided, thx @MrFlick

– dotahuanci
Nov 14 '18 at 17:35





sample data is provided, thx @MrFlick

– dotahuanci
Nov 14 '18 at 17:35












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305099%2fhow-to-map-more-than-10-different-line-types-in-ggplot2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305099%2fhow-to-map-more-than-10-different-line-types-in-ggplot2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine