From my understanding, the name ‘pig’ is believed to have derived from one of two sources. Firstly, it is believed that cavies were originally referred to as guinea ‘pigs’ due to their ‘squeaks and squeals’ (as rightly said by Sophie W). However, many people - as am I - are inclined to believe the name ‘pig’ was first adopted due to the fact that ‘European pigs were often kept in much the same way: allowed to wander about the homestead, eating scraps until they were fat enough to eat’.
On the other hand, the origins of the name 'guinea' is likely to remain a mystery, since numerous suggestions have been made.