eval() not working with ggplot, returns “non-numeric argument to binary operator”
up vote
0
down vote
favorite
I have the following ggplot element stored as text:
eval(parse(text = " annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
eval() returns error "non-numeric argument to binary operator" since it's trying to add the two parts together, but the plus sign is used differently with ggplot. Is there any way to dodge this problem?
r ggplot2
add a comment |
up vote
0
down vote
favorite
I have the following ggplot element stored as text:
eval(parse(text = " annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
eval() returns error "non-numeric argument to binary operator" since it's trying to add the two parts together, but the plus sign is used differently with ggplot. Is there any way to dodge this problem?
r ggplot2
1
What are you using theparse
function for? Since you are hard coding everything, would it not be easier to just have theannotate()
simply.
– Jrakru56
Nov 19 at 20:03
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.
– kkz
Nov 19 at 20:55
1
if that's the case, then you might be better off creating adata.frame
orlist
to hold yourx
,y
and 'label
– Jrakru56
Nov 19 at 20:59
1
Soemthing like this:dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))
– Jrakru56
Nov 19 at 21:08
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following ggplot element stored as text:
eval(parse(text = " annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
eval() returns error "non-numeric argument to binary operator" since it's trying to add the two parts together, but the plus sign is used differently with ggplot. Is there any way to dodge this problem?
r ggplot2
I have the following ggplot element stored as text:
eval(parse(text = " annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
eval() returns error "non-numeric argument to binary operator" since it's trying to add the two parts together, but the plus sign is used differently with ggplot. Is there any way to dodge this problem?
r ggplot2
r ggplot2
asked Nov 19 at 19:54
kkz
474
474
1
What are you using theparse
function for? Since you are hard coding everything, would it not be easier to just have theannotate()
simply.
– Jrakru56
Nov 19 at 20:03
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.
– kkz
Nov 19 at 20:55
1
if that's the case, then you might be better off creating adata.frame
orlist
to hold yourx
,y
and 'label
– Jrakru56
Nov 19 at 20:59
1
Soemthing like this:dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))
– Jrakru56
Nov 19 at 21:08
add a comment |
1
What are you using theparse
function for? Since you are hard coding everything, would it not be easier to just have theannotate()
simply.
– Jrakru56
Nov 19 at 20:03
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.
– kkz
Nov 19 at 20:55
1
if that's the case, then you might be better off creating adata.frame
orlist
to hold yourx
,y
and 'label
– Jrakru56
Nov 19 at 20:59
1
Soemthing like this:dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))
– Jrakru56
Nov 19 at 21:08
1
1
What are you using the
parse
function for? Since you are hard coding everything, would it not be easier to just have the annotate()
simply.– Jrakru56
Nov 19 at 20:03
What are you using the
parse
function for? Since you are hard coding everything, would it not be easier to just have the annotate()
simply.– Jrakru56
Nov 19 at 20:03
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.
– kkz
Nov 19 at 20:55
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.
– kkz
Nov 19 at 20:55
1
1
if that's the case, then you might be better off creating a
data.frame
or list
to hold your x
, y
and 'label
– Jrakru56
Nov 19 at 20:59
if that's the case, then you might be better off creating a
data.frame
or list
to hold your x
, y
and 'label
– Jrakru56
Nov 19 at 20:59
1
1
Soemthing like this:
dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))
– Jrakru56
Nov 19 at 21:08
Soemthing like this:
dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))
– Jrakru56
Nov 19 at 21:08
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
This was solved by putting ggplot() +
at the start of the code, i.e.
eval(parse(text = "ggplot() +
annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
add a comment |
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',
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381724%2feval-not-working-with-ggplot-returns-non-numeric-argument-to-binary-operator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
This was solved by putting ggplot() +
at the start of the code, i.e.
eval(parse(text = "ggplot() +
annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
add a comment |
up vote
0
down vote
accepted
This was solved by putting ggplot() +
at the start of the code, i.e.
eval(parse(text = "ggplot() +
annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
This was solved by putting ggplot() +
at the start of the code, i.e.
eval(parse(text = "ggplot() +
annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
This was solved by putting ggplot() +
at the start of the code, i.e.
eval(parse(text = "ggplot() +
annotate('text', as.Date('2013-12-31'), 30.31049879 * 1.02,
label = paste0( 19.48 , percent( 0.055 )), color = 'Blue') +
annotate('text', as.Date('2013-12-31'), 33.341548669 * 1.02,
label = paste0( 21.43 , percent( 0.048 )), color = 'Blue') "))
answered Nov 20 at 11:15
kkz
474
474
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381724%2feval-not-working-with-ggplot-returns-non-numeric-argument-to-binary-operator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
What are you using the
parse
function for? Since you are hard coding everything, would it not be easier to just have theannotate()
simply.– Jrakru56
Nov 19 at 20:03
@Jrakru56 I have about twenty of those annotations so I figured out it might be easier to add them using a loop instead of hardcoding twenty rows.
– kkz
Nov 19 at 20:55
1
if that's the case, then you might be better off creating a
data.frame
orlist
to hold yourx
,y
and 'label
– Jrakru56
Nov 19 at 20:59
1
Soemthing like this:
dt<- mtcars; ggplot(data=dt) + geom_point(aes(x=mpg, y =hp )) + geom_text(aes(label = rownames(dt), x =mpg, y = hp))
– Jrakru56
Nov 19 at 21:08